View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
StumpedAgain StumpedAgain is offline
external usenet poster
 
Posts: 192
Default Looping through clumns and switch to rows

Here's my solution. It's a littel messy, but it works!

(Mind any text wrapping)

Sub Reorganize()

Dim glcount, numrows, i, j, l, k As Integer
Dim currentrow As Integer

With ActiveSheet.Range("A1") 'or wherever you start
numrows = Range(.Offset(0, 0), .End(xlDown)).Rows.Count
End With

Range("A1").Select

For l = 1 To numrows

With ActiveSheet.Range("A1").Offset(k, 0) 'or wherever you start
MsgBox (ActiveSheet.Range("A1").Offset(k, 0).Address)
glcount = Range(.Offset(0, 1), .End(xlToRight)).Columns.Count
End With

j = 0

For i = 1 To glcount - 1
currentrow = Range("A1").Offset(i + j + k - 1, 0).Row
Rows(currentrow).Offset(1, 0).Select
Selection.Insert Shift:=xlDown
Cells(j + 1 + k, i + 2).Cut Destination:=Range("A1").Offset(i + k, 1)
Cells(j + 1 + k, "A").Copy Destination:=Range("A1").Offset(i + k, 0)
Next i

k = k + i

Next l

End Sub

"mjmcevoy" wrote:

Nope. First column contains the customer names. over 100 customers.

Then the rest of the columes contain account numbers that pretain to each
customer. No blank columns in between

"StumpedAgain" wrote:

Is there a column between Customer X and the first number? Are there any
empty columns between the numbers?

"mjmcevoy" wrote:

I need to convert

Customer B 1457895 1248875 45345345 45345434
Customer X 6548464 6549846 68462184 6548414 6354654


to

Customer B 1457895
Customer B 1248875
Customer B 45345345
Customer B 45345434
Customer X 6548464
Customer X 6549846
Customer X 68462184
Customer X 6548414
Customer X 6354654

It is several lines ad as many as 225 columns per line.

Any help is appreciated.