Hi there all, please can someone help with a basic triple loop scenario:
I have 2 tables, A and B, one in workbook 1, the other in workbook 2.
Table A is basically table B but with empty columns removed, so you just have columns with rows where values are in. Table B is a blank uncondensed table with all the possible column headers had table A not been condensed.
In VBA I need to find a way of getting Excel to look for the column header codes in Table A, find the value that sits underneath it, then scan the column header row in table B to find a match and then transfer the value from A into B. This has to loop until all column values for that row in table A have been pasted into B.
Then it needs to advance to the next row in table A, or if it is blank then exit. For each new row looked at in table A, this should also start a new row in table B.
So far I have code that does not do anything and I am not sure why:
I have 2 tables, A and B, one in workbook 1, the other in workbook 2.
Table A is basically table B but with empty columns removed, so you just have columns with rows where values are in. Table B is a blank uncondensed table with all the possible column headers had table A not been condensed.
In VBA I need to find a way of getting Excel to look for the column header codes in Table A, find the value that sits underneath it, then scan the column header row in table B to find a match and then transfer the value from A into B. This has to loop until all column values for that row in table A have been pasted into B.
Then it needs to advance to the next row in table A, or if it is blank then exit. For each new row looked at in table A, this should also start a new row in table B.
So far I have code that does not do anything and I am not sure why:
Code:
DestIndex = 1
For sourcerow = 4 To 250
If Not Workbooks(SourceWorkbookName).Sheets("Sheet 1").Cells(sourcerow, 7) = "" Then
For sourcecolumn = 9 To 50
If Not Workbooks(SourceWorkbookName).Sheets("Sheet 1").Cells(3, sourcecolumn) = "" Then
sourcecode = Workbooks(SourceWorkbookName).Sheets("Sheet 1").Cells(3, sourcecolumn)
Do
If Workbooks(DestWorkbookName).Sheets("Sheet 1").Cells(5, DestIndex) = sourcecode Then
sourcevalue = Workbooks(SourceWorkbookName).Sheets("Sheet 1").Cells(4, sourcecolumn)
Workbooks(DestWorkbookName).Sheets("Sheet 1").Cells(6, DestIndex) = sourcevalue
DestIndex = DestIndex + 1
Exit Do
Else
DestIndex = DestIndex + 1
End If
Loop Until Workbooks(DestWorkbookName).Sheets("Sheet 1").Cells(5, DestIndex) = ""
Else
Exit For
End If
Next sourcecolumn
Else
Exit For
End If
Next sourcerow