Need some help with a VBA script for excel to convert data in a column into a new Row if certain column not empty. Duplicate the initial data in a couple of primary columns into a new row and copy/condense the data from another column into that new row if the cell in the column is not empty. My file has 1,000's of records and I don't have the time to individually separate them. Best if seen visually below (sorry not enough rep to post image)
Starts like this.
Col1.......Col2.....Col3.....Col4
ItemA.....$2.........................
ItemB.....$2........$4.............
ItemC.....$6.........................
ItemD.....$2........$3.........$5
ItemE.....$9.........................
Finish like this
Col1.......Col2
ItemA.....$2
ItemB.....$2
ItemB.....$4
ItemC.....$6
ItemD.....$2
ItemD.....$3
ItemD.....$5
ItemE.....$9
This is how I would handle in vb and html with recordset loops. Just need advice on excel where recordset or range is determined and how it starts through columns.
Dim Col1, Col2, Col3, Col4, RowData, CondenseData, FinalData
FinalData = ""
While ((RS.Items__numRows <> 0) AND (NOT RS.Items.EOF)) 'recordset loop how in Excel?
CondenseData = ""
Col1 = RS.Col1Data 'how to go from column to column in row in excel?
Col2 = RS.Col2Data
Col3 = RS.Col3Data
Col4 = RS.Col4Data
If Not IsNull(Col2) Then
CondenseData = Col1 & ", " & Col2
RowData = CondenseData & "<br />" ' create a new row with the revised data if not empty?
End If
If Not IsNull(Col3) Then
CondenseData = Col1 & ", " & Col3
RowData = CondenseData & "<br />"
End If
If Not IsNull(Col4) Then
CondenseData = Col1 & ", " & Col4
RowData = CondenseData & "<br />"
End If
FinalData = FinalData & RowData
RS.Items__index=RS.Items__index+1
RS.Items__numRows=RS.Items__numRows-1
RS.Items.MoveNext()
Wend