Re: Combine two Macro Codes together
@ SO
I took my syntax and placed into a loop like this:
Code
last_r2 = Sheets("sheet3").Range("A3").End(xlDown).Row ' this is the column with the different dates
last_r1 = Sheets("sheet2").Range("A3").End(xlDown).Row
last_column1 = Sheets("sheet2").Range("B2").SpecialCells(xlCellTypeLastCell).Column
last_column2 = Sheets("sheet3").Range("B1").SpecialCells(xlCellTypeLastCell).Column
For i = 6 To last_r2
Dim lngcolumn8 As Long: lngcolumn8 = 12
Do Until IsEmpty(Sheets("sheet3").Cells(2, lngcolumn8))
If Sheets("sheet3").Cells(last_r2, 1) > Sheets("sheet3").Cells(last_r2 - 1, 1) Then 'if the current date is larger than the previous one then
Sheets("sheet3").Cells(last_r2 - 1, lngcolumn8).Copy
Sheets("sheet3").Cells(last_r2, lngcolumn8).Insert shift:=xlDown
lngcolumn8 = lngcolumn8 + 4
End If
Loop
Dim lngloop As Long: lngloop = 12
Do Until IsEmpty(Sheets("sheet3").Cells(1, lngloop))
For Each cell In Sheets("sheet3").Range(Sheets("sheet3").Cells(last_r2, 9), Sheets("sheet3").Cells(last_r2, last_column2))
If IsEmpty(cell) Then
cell = Application.WorksheetFunction.Index(Sheets("sheet2").Range(Sheets("sheet2").Cells(1, 1), Sheets("sheet2").Cells(last_r1, last_column1)), Application.Match(CLng(Sheets("sheet3").Cells(last_r2, 1)), Sheets("sheet2").Range(Sheets("sheet2").Cells(1, 1), Sheets("sheet2").Cells(last_r1, 1)), 0), Application.Match(Sheets("sheet3").Cells(1, lngloop), Sheets("sheet2").Range(Sheets("sheet2").Cells(2, 1), Sheets("sheet2").Cells(2, last_column1)), 0) + 1)
lngloop = lngloop + 4
End If
Next
Loop
Next
Display More
And it works