#1   Report Post  
Posted to microsoft.public.excel.misc
Dave
 
Posts: n/a
Default Columns to rows

I have a spreadsheet which contains rows which have part number data in them
(in this case the spreadsheet is created from a Bill of Material report which
has the components' info in the rows).

This sheet has reference designator (locations of components on a circuit
board) column which contains a variable number of locations.

I can do a text to columns parse on the location column to get x number of
columns with each reference designator in a separate colum. How do I/ can I
repeat the part number in column A with a separate individual reference
designator?

I want to end up with something like:

Original: PN XYZ | locations x2,y2,z2

Desired result: PN XYZ | location X2
PN XYZ | location Y2
PN XYZ | location Z2

Excel is a wonderful tool, but I'm still relatively new to more
sophisticated features. Is this doable?

Thanks in advance,

Dave
  #2   Report Post  
Posted to microsoft.public.excel.misc
David McRitchie
 
Posts: n/a
Default Columns to rows

Hi Dave......, (not revealing your full name is not very friendly)

The following macro will do what you ask, though I'm not sure if that is 1 column or 2 column
in the stub before the arguments will assume it is 1,
if it is 1 then use
stub_columns = 1 'columns A:
arg_columns = 3 'columns B for 3 columns

Sub Split_2_splits()
Dim stub_columns As Long, arg_columns As Long, lastrow As Long
stub_columns = 3 'columns A:B
arg_columns = 3 'columns C for 3 columns
Dim oldSht As Worksheet, newSht As Worksheet
Dim r As Long, c As Long, nr As Long, ac As Long
Dim ac_from As Long, ac_to As Long
ac_from = stub_columns + 1
ac_to = stub_columns + arg_columns
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
nr = 0

Set oldSht = ActiveSheet
Application.DisplayAlerts = False
On Error Resume Next
Sheets("new_work").Delete
On Error GoTo 0
Application.DisplayAlerts = True

ActiveWorkbook.Worksheets.Add(After:=ActiveSheet). Name = "new_work"
Set newSht = ActiveSheet
If lastrow < 11 Then MsgBox lastrow
For r = 1 To lastrow
For ac = ac_from To ac_to
If Trim(oldSht.Cells(r, ac)) < "" Then
nr = nr + 1
For c = 1 To stub_columns
newSht.Cells(nr, c).Formula = oldSht.Cells(r, c).Formula
newSht.Cells(nr, c).NumberFormat = oldSht.Cells(r, c).NumberFormat
newSht.Cells(nr, c).Font.ColorIndex = oldSht.Cells(r, c).Font.ColorIndex
Next c
newSht.Cells(nr, ac_from).Formula = oldSht.Cells(r, ac).Formula
newSht.Cells(nr, ac_from).NumberFormat = oldSht.Cells(r, ac).NumberFormat
newSht.Cells(nr, ac_from).Font.ColorIndex = oldSht.Cells(r, ac).Font.ColorIndex
End If
Next ac
Next r
End Sub


If not familiar with macros then see
http://www.mvps.org/dmcritchie/excel....htm#havemacro

---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Dave" wrote in message ...
I have a spreadsheet which contains rows which have part number data in them
(in this case the spreadsheet is created from a Bill of Material report which
has the components' info in the rows).

This sheet has reference designator (locations of components on a circuit
board) column which contains a variable number of locations.

I can do a text to columns parse on the location column to get x number of
columns with each reference designator in a separate colum. How do I/ can I
repeat the part number in column A with a separate individual reference
designator?

I want to end up with something like:

Original: PN XYZ | locations x2,y2,z2

Desired result: PN XYZ | location X2
PN XYZ | location Y2
PN XYZ | location Z2

Excel is a wonderful tool, but I'm still relatively new to more
sophisticated features. Is this doable?

Thanks in advance,

Dave



  #3   Report Post  
Posted to microsoft.public.excel.misc
Dave
 
Posts: n/a
Default Columns to rows

David,

Woaaa! That's a big macro! Thanks much for your help. I have used macros
before, but not this sophisticated. I'll take some time to digest this.

But thanks again. Your help is much appreciated.

Oh, my name is Dave Schiffer

"David McRitchie" wrote:

Hi Dave......, (not revealing your full name is not very friendly)

The following macro will do what you ask, though I'm not sure if that is 1 column or 2 column
in the stub before the arguments will assume it is 1,
if it is 1 then use
stub_columns = 1 'columns A:
arg_columns = 3 'columns B for 3 columns

Sub Split_2_splits()
Dim stub_columns As Long, arg_columns As Long, lastrow As Long
stub_columns = 3 'columns A:B
arg_columns = 3 'columns C for 3 columns
Dim oldSht As Worksheet, newSht As Worksheet
Dim r As Long, c As Long, nr As Long, ac As Long
Dim ac_from As Long, ac_to As Long
ac_from = stub_columns + 1
ac_to = stub_columns + arg_columns
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
nr = 0

Set oldSht = ActiveSheet
Application.DisplayAlerts = False
On Error Resume Next
Sheets("new_work").Delete
On Error GoTo 0
Application.DisplayAlerts = True

ActiveWorkbook.Worksheets.Add(After:=ActiveSheet). Name = "new_work"
Set newSht = ActiveSheet
If lastrow < 11 Then MsgBox lastrow
For r = 1 To lastrow
For ac = ac_from To ac_to
If Trim(oldSht.Cells(r, ac)) < "" Then
nr = nr + 1
For c = 1 To stub_columns
newSht.Cells(nr, c).Formula = oldSht.Cells(r, c).Formula
newSht.Cells(nr, c).NumberFormat = oldSht.Cells(r, c).NumberFormat
newSht.Cells(nr, c).Font.ColorIndex = oldSht.Cells(r, c).Font.ColorIndex
Next c
newSht.Cells(nr, ac_from).Formula = oldSht.Cells(r, ac).Formula
newSht.Cells(nr, ac_from).NumberFormat = oldSht.Cells(r, ac).NumberFormat
newSht.Cells(nr, ac_from).Font.ColorIndex = oldSht.Cells(r, ac).Font.ColorIndex
End If
Next ac
Next r
End Sub


If not familiar with macros then see
http://www.mvps.org/dmcritchie/excel....htm#havemacro

---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Dave" wrote in message ...
I have a spreadsheet which contains rows which have part number data in them
(in this case the spreadsheet is created from a Bill of Material report which
has the components' info in the rows).

This sheet has reference designator (locations of components on a circuit
board) column which contains a variable number of locations.

I can do a text to columns parse on the location column to get x number of
columns with each reference designator in a separate colum. How do I/ can I
repeat the part number in column A with a separate individual reference
designator?

I want to end up with something like:

Original: PN XYZ | locations x2,y2,z2

Desired result: PN XYZ | location X2
PN XYZ | location Y2
PN XYZ | location Z2

Excel is a wonderful tool, but I'm still relatively new to more
sophisticated features. Is this doable?

Thanks in advance,

Dave




  #4   Report Post  
Posted to microsoft.public.excel.misc
David McRitchie
 
Posts: n/a
Default Columns to rows

Hi Dave,
You're welcome. The macro is a bit bigger now, see
SNAKECOLS, How to snake columns to use fewer pages
http://www.mvps.org/dmcritchie/excel...l.htm3simplify
look for Split_2_splits() and your own customization would be needed.

It will copy an paste the formats used
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm

"Dave" wrote
Woaaa! That's a big macro! Thanks much for your help. I have used macros
before, but not this sophisticated. I'll take some time to digest this.

But thanks again. Your help is much appreciated.
Oh, my name is Dave Schiffer



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rows & Columns in Excel seadragon69 Excel Worksheet Functions 2 December 7th 05 05:54 PM
convert columns to rows & rows to columns ROCKWARRIOR Excel Discussion (Misc queries) 2 September 23rd 05 06:31 PM
How to swap rows and columns? [email protected] Excel Discussion (Misc queries) 5 September 21st 05 08:07 AM
hidden rows & columns slow file open Simon Shaw Excel Discussion (Misc queries) 0 April 5th 05 12:21 AM
Removing Near-Duplicate Rows, Leaving Those w/Most Data in Specific Columns foofoo Excel Discussion (Misc queries) 1 April 2nd 05 12:02 AM


All times are GMT +1. The time now is 05:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"