Taul
Well-known Member
- Joined
- Oct 24, 2004
- Messages
- 767
- Office Version
- 2019
- Platform
- Windows
Hi,
I could do with some assistance please. I have data laid out as follows:-
Headers in row 5 and Data in columns A to T (approx. 300 rows of data)
Column A will always shave data in it, so I’m using that column to reference the “lastrow”
Columns G to K will have company names (with some blank) and I need to loop through column G and for each occurrence of data (a company name) I need to paste the company name in the next available row in column F and then repeat for columns H, I J & K
The code I have so far works for the first column but using the offset command pastes the wrong data to column A to E
Can anyone assist in getting a loop within a loop to work correctly please.
I have a feeling it may involve using two variable j & i but I can’t figure that out.
The blue text is not working, so ...
Up to Row 12 is the source data,
Row 13 and below is what is required after the macro is run (should have been blue)
Excel 2010
<tbody>
[TD="align: center"]5[/TD]
[TD="bgcolor: #C6E0B4, align: center"]Date[/TD]
[TD="bgcolor: #C6E0B4, align: center"]Module[/TD]
[TD="bgcolor: #C6E0B4, align: center"]Name[/TD]
[TD="bgcolor: #C6E0B4, align: center"]Category[/TD]
[TD="bgcolor: #C6E0B4, align: center"]Project[/TD]
[TD="align: center"]6[/TD]
[TD="align: center"]19-04-18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]7[/TD]
[TD="align: center"]24-04-18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]8[/TD]
[TD="align: center"]25-04-18[/TD]
[TD="align: center"]9[/TD]
[TD="align: center"]11-04-18[/TD]
[TD="align: center"]10[/TD]
[TD="align: center"]11-04-18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]12-04-18[/TD]
[TD="align: center"]12[/TD]
[TD="align: center"]16-04-18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]13[/TD]
[TD="align: center"]19-04-18[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]14[/TD]
[TD="align: center"]25-04-18[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]11-04-18[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]16[/TD]
[TD="align: center"]11-04-18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]17[/TD]
[TD="align: center"]12-04-18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]25-04-18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]19[/TD]
[TD="align: center"]11-04-18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]20[/TD]
[TD="align: center"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]21[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
</tbody>
I could do with some assistance please. I have data laid out as follows:-
Headers in row 5 and Data in columns A to T (approx. 300 rows of data)
Column A will always shave data in it, so I’m using that column to reference the “lastrow”
Columns G to K will have company names (with some blank) and I need to loop through column G and for each occurrence of data (a company name) I need to paste the company name in the next available row in column F and then repeat for columns H, I J & K
The code I have so far works for the first column but using the offset command pastes the wrong data to column A to E
Can anyone assist in getting a loop within a loop to work correctly please.
I have a feeling it may involve using two variable j & i but I can’t figure that out.
The blue text is not working, so ...
Up to Row 12 is the source data,
Row 13 and below is what is required after the macro is run (should have been blue)
Excel 2010
A | B | C | D | E | F | G | H | I | J | K | |
---|---|---|---|---|---|---|---|---|---|---|---|
Fab 1 | Fab 2 | Fab 3 | Fab 4 | Fab 5 | Fab 6 | ||||||
R1 | GWA | BW | Project 1 | Fab 1 | Fab 2 | ||||||
R1 | GWA | BW | Project 2 | Fab 2 | |||||||
R3 | MCK | RY | Project 3 | Fab 3 | Fab 6 | Fab 9 | |||||
R4 | AF | CV | Project 4 | Fab 2 | Fab 3 | ||||||
R4 | AF | CV | Project 5 | Fab 5 | Fab 7 | Fab 6 | |||||
R4 | AF | CV | Project 6 | Fab 6 | Fab 2 | ||||||
R4 | AF | CV | Project 7 | Fab 7 | |||||||
Row 6 | GWA | BW | Project 1 | Fab 2 | |||||||
Row 8 | MCK | RY | Project 3 | Fab 6 | |||||||
Row 9 | AF | CV | Project 4 | Fab 3 | |||||||
Row 10 | AF | CV | Project 5 | Fab 7 | |||||||
Row 11 | AF | CV | Project 6 | Fab 2 | |||||||
Row 8 | MCK | RY | Project 3 | Fab 9 | |||||||
Row 10 | AF | CV | Project 5 | Fab 6 | |||||||
After macro runs, the data in BLUE should be pasted |
<tbody>
[TD="align: center"]5[/TD]
[TD="bgcolor: #C6E0B4, align: center"]Date[/TD]
[TD="bgcolor: #C6E0B4, align: center"]Module[/TD]
[TD="bgcolor: #C6E0B4, align: center"]Name[/TD]
[TD="bgcolor: #C6E0B4, align: center"]Category[/TD]
[TD="bgcolor: #C6E0B4, align: center"]Project[/TD]
[TD="align: center"]6[/TD]
[TD="align: center"]19-04-18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]7[/TD]
[TD="align: center"]24-04-18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]8[/TD]
[TD="align: center"]25-04-18[/TD]
[TD="align: center"]9[/TD]
[TD="align: center"]11-04-18[/TD]
[TD="align: center"]10[/TD]
[TD="align: center"]11-04-18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]12-04-18[/TD]
[TD="align: center"]12[/TD]
[TD="align: center"]16-04-18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]13[/TD]
[TD="align: center"]19-04-18[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]14[/TD]
[TD="align: center"]25-04-18[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]15[/TD]
[TD="align: center"]11-04-18[/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"][/TD]
[TD="align: center"]16[/TD]
[TD="align: center"]11-04-18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]17[/TD]
[TD="align: center"]12-04-18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]18[/TD]
[TD="align: center"]25-04-18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]19[/TD]
[TD="align: center"]11-04-18[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]20[/TD]
[TD="align: center"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: center"]21[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
</tbody>
Sheet1
Code:
Sub AlignFabs()
'Application.ScreenUpdating = False
'Application.Calculation = xlCalculationManual
''**** Loop Through Rows of Fab Names ****
For Each Col In Array("G", "H", "I", "J", "K")
cntr = 0
For Each co In Sheet1.Range(Col & "6:" & Col & Sheet1.Range(Col & "65536").End(xlUp).Row + 0)
lastrow = Sheet1.Range("A65536").End(xlUp).Offset(1, 0).Row 'define the row increment on the Destination sheet
If co.Offset(0, 0).Value <> "" Then
Sheet1.Range("A" & lastrow).Value = co.Offset(0, -6) 'Date
Sheet1.Range("B" & lastrow).Value = "Copy" 'ideally paste the row number it came from
Sheet1.Range("C" & lastrow).Value = co.Offset(0, -4) 'Name
Sheet1.Range("D" & lastrow).Value = co.Offset(0, -3) 'Category
Sheet1.Range("E" & lastrow).Value = co.Offset(0, -2) 'Project
Sheet1.Range("F" & lastrow).Value = co.Offset(0, 0) 'Fab1 column F
End If
cntr = cntr + 1
Next co
Next Col
'Application.Calculation = xlCalculationAutomatic
'Application.ScreenUpdating = True
End Sub