I have an If loop comparing values. I am trying to move data from sheet "clean18" to sheet "monthcompare" based on the criteria. Everything in the code works. there are no errors. I just can't get the data from "clean 18" to list in "monthcompare" correctly. I would like the "clean18" data to be copied to "monthcompare" one row at a time. It is instead copying to the row associated with the clean 18 data. so I have spaces.
What am I missing?
Code:
Sub getsalesdata()
Dim i As Integer
Dim r2 As Integer
Dim lrow18, lrow19, lrowmcompare As Long
Dim range18, range19 As Range
Dim colnum, monthselect As Variant
r2 = 2
monthselect = InputBox("Select month to compare")
colnum = Application.WorksheetFunction.match(monthselect, Sheets("Clean18").Range("a1:n1"), 0)
lrow18 = Sheet11.Cells(Rows.Count, 1).End(xlUp).Row
lrow19 = Sheet12.Cells(Rows.Count, 1).End(xlUp).Row
lrowmcompare = Sheet10.Cells(Rows.Count, 1).End(xlUp).Row
MsgBox colnum
Sheet10.Range("a2:b" & lrow18).Clear
For i = 2 To lrow18
If Sheets("clean18").Cells(i, colnum).Value > 0 Then
Sheets("MonthCompare").Cells(r2, 1).Value = Sheets("Clean18").Cells(i, 1).Value
Sheets("monthcompare").Cells(r2, 2).Value = Sheets("clean18").Cells(i, 2).Value
End If
r2 = r2 + 1
Next i
End Sub