View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
excelmad excelmad is offline
external usenet poster
 
Posts: 9
Default rows to columns and colums to rows

Some time ago, I had the same question on the rows to columns on reference
(your 2nd scenario). Here was the response I received unfortunately I don't
remember from whom. I did change it a bit to create a new sheet but this
should work provided your data is within column A:K if not change the range
to match your case.

Public Sub ProcessData2()
Dim cColumns As Long
Dim i As Long
Dim iLastRow As Long
Dim iLastCol As Long
Dim cMaxCols As Long
Dim cell As Range
Dim sh As Worksheet

Columns("A:K").Select
Columns("A:K").Copy
Sheets.Add
Range("A1").Select
ActiveSheet.Paste

With ActiveSheet

cColumns = .Cells(1, .Columns.Count).End(xlToLeft).Column
iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = iLastRow To 2 Step -1
If .Cells(i, "A").Value = .Cells(i - 1, "A").Value Then
iLastCol = .Cells(i, .Columns.Count) _
..End(xlToLeft).Column
..Cells(i, "B").Resize(1, iLastCol - 1).Copy .Cells(i - 1, cColumns + 1)
If iLastCol + cColumns cMaxCols Then _
cMaxCols = iLastCol + cColumns - 1
..Rows(i).Delete
End If
Next i

'now add headings
For i = cColumns + 1 To cMaxCols Step cColumns - 1
..Range("B1").Resize(, cColumns - 1).Copy .Cells(1, i)
Next i

End With

MsgBox "Run Complete"

End Sub

Now I have the same question as your 1st scenario (columns to rows).

"Bravo" wrote:

On Oct 5, 2:12 am, JP wrote:
Hello,

I've written something similar to what you want, I'll try to get the
code for you shortly.

--JP



"Bravo" wrote:
Hi,


I am New to excel programing in VB,
I want to know the code how to change the row to colume and colume to
row


and can i can i know where i learn online for programing for excel.


for eg if i have :
abc 1
abc 2
abc 3


xyz 2
xyz 3
xyz 5


hgf 3
hgf 4
hgf 3


and i have a button call CHANGE


when i click on the button CHANGE


abc 1 2 3
xyz 2 3 5
hgf 3 4 3- Hide quoted text -


- Show quoted text -


JP

can you please share the code with me