Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to switch data between rows and columns by using programming?

I have text file like following:
NAME: Mike
price: $12
UNIT: 3
NAME: Tom
price: $12
UNIT: 3
NAME: SMITH
PRICE: $16
UNIT: 6
NAME: Jone
price: $22
UNIT: 3
NAME: Yang
price: $32
UNIT: 5
NAME: Yubin
PRICE: $6
UNIT: 10

How to switch to Excel file like following style?

NAME price UNIT
Mike $12 3
Tom $12 3
SMITH $16 6
Jone $22 3
Yang $32 5
Yubin $6 10

thank you!


  #2   Report Post  
Posted to microsoft.public.excel.programming
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



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
Switch from Columns <- Rows Alain Dekker Excel Discussion (Misc queries) 5 July 29th 09 02:49 PM
+++Switch Rows & Columns Ian Excel Worksheet Functions 1 April 13th 07 12:46 PM
How to switch position of columns and rows respectively? Jaleel Excel Worksheet Functions 1 November 1st 06 11:03 PM
switch rows and columns tomba545 New Users to Excel 3 June 6th 06 09:48 AM
Switch Rows and Columns Bonnie Excel Discussion (Misc queries) 3 March 3rd 05 03:38 PM


All times are GMT +1. The time now is 10:57 PM.

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

About Us

"It's about Microsoft Excel"