View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
merjet merjet is offline
external usenet poster
 
Posts: 812
Default How to switch data between rows and columns by using programming?

You could put the text file data in column A of Sheet1
and then run this macro:

Sub macro1()
Dim iRow As Integer
Dim iRow2 As Integer
Dim ws As Worksheet

Set ws = Sheets("Sheet1")
ws.Range("C1") = "NAME"
ws.Range("D1") = "PRICE"
ws.Range("E1") = "UNIT"
iRow = 3
Do Until ws.Cells(iRow, 1) = ""
ws.Cells(1 + iRow / 3, 3) = Right(ws.Cells(iRow - 2, 1),
Len(ws.Cells(iRow - 2, 1)) - 6)
ws.Cells(1 + iRow / 3, 4) = Right(ws.Cells(iRow - 1, 1),
Len(ws.Cells(iRow - 1, 1)) - 7)
ws.Cells(1 + iRow / 3, 5) = Right(ws.Cells(iRow, 1),
Len(ws.Cells(iRow, 1)) - 6)
iRow = iRow + 3
Loop
End Sub

HTH,
Merjet