I've been writing a code to pull data into a sheet, and am trying to delete a bunch of unwanted columns. On the first range select for deleting, I keep keep getting a "method of range" error. I have tried using On Error goto - 1 and this just runs forever. However, If I change one of the parameters to $column, and run, then revert to original, the code will run fine. Is there a better way to write this to avoid the error?
Dim newvoyagerng As Range
Set newvoyagerng = sht6.Range("AN2:AN" & Rows.Count)
With sht6
For Each cell In newvoyagerng
If cell.value <> "" And _
cell.value <> "N/A" And _
cell.value <> "0" Then 'if cells have value, check for mismatch. If mismatch, paste in sheet 12
If cell.Offset(0, -1) <> "0" And _
cell.Offset(0, -1) <> "N/A" And _
cell.Offset(0, -1) <> cell.value Then
cell.EntireRow.Copy
sht11.Cells(Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
End If
Next cell
End With
If sht11.Range("A2") <> "" Then
sht11.Columns("C:G").Select ' Error occurs on this line replacing with any variation and returning to this form let it run...
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
sht11.Columns("E:AG").Select
Selection.Delete Shift:=xlToLeft
sht11.Columns("G:H").Select
Selection.Delete Shift:=xlToLeft
End If