I'm writing the below snippet to try and search through every other column of a range and find cells that aren't blank. I want to fill the offset (0,1) with "kg". Can someone help me re-write this? I can't find any literature online about it. It keeps giving me either error type mismatch or error out of memory. I have made sure that all my variables and recordsets (I'm writing a very long code to export different queries with formatting) are set to nothing so I'm not sure what the out of memory error could be
Code:
Dim i As Long
Dim wks As Excel.Worksheet
For i = 3 To 22 Step 2
With wks.Range(wks.Cells(Lrow + 9, i), "C" & Lrow + 19)
If wks.Cells.Value <> "" Then
wks.Cells.Offset(0, 1).Value = "kg"
End If
End With
Next i
IF I change the code to this, then nothing happens. The spreadsheet exports and there are no 'kg' markers.
Code:
For i = 3 To 22 Step 2
With wks.Range(wks.Cells(Lrow + 9, i), "C" & Lrow2)
If Value <> "" Then
.Offset(0, 1).Value = "kg"
End If
End With
Next i