Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
I need to write a macro that will do the following : Example Input Col 1 Col2 COl3 Col4 Col5 Col6 StockCode 010 020 030 040 050 1818560 1 3 5 1818620 1 2 1818630 3 6 2 1818530 3 1 3 1956220 4 3 2 3 After Macro Out Put New Sheet Col1 StockCode 1818560010 1 1818560020 3 1818560030 5 1818620010 1 1818620020 2 1818630010 3 1818630020 6 1818630030 2 1818530010 3 1818530020 1 1818530030 3 1956220010 4 1956220020 3 1956220040 2 1956220050 3 Please be advise that i have approximately 10000 rows to convert. I urgently require some help Many Thanks AQ *** Sent via Devdex http://www.devdex.com *** Don't just participate in USENET...get rewarded for it! |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I love short exercises like this. Try this:
'-------------------------------------------------------------------- Sub ConvertTable() 'Convert a N by M table from Sheet1 to a K by 2 table on Sheet2 Dim SPivot As Range, DPivot As Range 'Source and Designation Dim iCol As Integer, iRow As Integer 'Column and Row Counts Dim iList As Integer 'Count number of row on list 'Set Source Pivot at Stock Code line column 1 Set SPivot = ThisWorkbook.Sheets("Sheet1").[A2] 'Set Designation Pivot on Sheet 2 Cell A1 Set DPivot = ThisWorkbook.Sheets("Sheet2").[A1] 'Clear previous report DPivot.Offset(1, 0).CurrentRegion.ClearContents 'Reset column heading of designation DPivot.Offset(0, 0) = "Column 1" DPivot.Offset(0, 1) = "Column 2" iRow = 1 'Assumming no blank rows between headings and data iList = 1 'Assumming the designation list starts from row 2 'Run through each row Do While IsEmpty(SPivot.Offset(iRow, 0)) = False iCol = 1 'Run through each column Do While IsEmpty(SPivot.Offset(0, iCol)) = False 'Collect data only if the selected cell is not blank If IsEmpty(SPivot.Offset(iRow, iCol)) = False Then 'Increase list size iList = iList + 1 'Column 1 data DPivot.Offset(iList, 0) = SPivot.Offset(0, iCol) & _ SPivot.Offset(iRow, 0) 'Column 2 Data DPivot.Offset(iList, 1) = SPivot.Offset(iRow, iCol) End If iCol = iCol + 1 Loop iRow = iRow + 1 Loop End Sub '------------------------------------------------------------ "AQ Mahomed" wrote: Hi I need to write a macro that will do the following : Example Input Col 1 Col2 COl3 Col4 Col5 Col6 StockCode 010 020 030 040 050 1818560 1 3 5 1818620 1 2 1818630 3 6 2 1818530 3 1 3 1956220 4 3 2 3 After Macro Out Put New Sheet Col1 StockCode 1818560010 1 1818560020 3 1818560030 5 1818620010 1 1818620020 2 1818630010 3 1818630020 6 1818630030 2 1818530010 3 1818530020 1 1818530030 3 1956220010 4 1956220020 3 1956220040 2 1956220050 3 Please be advise that i have approximately 10000 rows to convert. I urgently require some help Many Thanks AQ *** Sent via Devdex http://www.devdex.com *** Don't just participate in USENET...get rewarded for it! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort | Excel Worksheet Functions | |||
My excel macro recorder no longer shows up when recording macro | Excel Discussion (Misc queries) | |||
My excel macro recorder no longer shows up when recording macro | Excel Discussion (Misc queries) | |||
Excel Macro Issue Trying to autorun Macro Upon Opening Worksheet | Excel Programming |