next
03-03-2008, 04:05 PM
Option Explicit
Sub Test()
Dim LTD_xls As Worksheet, Open_dif As Worksheet
Dim rLTD As Range, rOPN As Range
Set LTD_xls = Workbooks("LTD Open.xls").Worksheets("open")
Set Open_dif = Workbooks("open.dif").Worksheets("open")
For Each rLTD In LTD_xls.Range("A2:A")
If IsEmpty(rLTD) Then
Exit For
End If
For Each rOPN In Open_dif.Range("A2:A")
If IsEmpty(rOPN) Then
Exit For
End If
If (rOPN = rLTD) Then
rOPN.EntireRow.Delete shift:=xlUp
End If
Next rOPN
Next rLTD
End Sub
Basicaly i have 2 sheets, this code "supposably" skans each cell in first column in Workbooks("LTD Open.xls").Worksheets("open") and matches it against Workbooks("open.dif").Worksheets("open") first column.
If identical cell cannot be found then row should be removed.
My Problem:
I get an error as soon as i get to For Each rLTD In LTD_xls.Range("A2:A")
which is the first "For". It sais: "Method "Range" of object "_Worksheet" failed". What am i doing wrong?
BTW, how can i skip one step in a loop if a value is not a number?
If i use this code:
If Not IsNumeric(rLTD) Then
Next rLTD
End If
blah blah blah...
Next rLTD
i get an error: "Next Without For" <- or something like this. What's wrong here?
Thanks!
Sub Test()
Dim LTD_xls As Worksheet, Open_dif As Worksheet
Dim rLTD As Range, rOPN As Range
Set LTD_xls = Workbooks("LTD Open.xls").Worksheets("open")
Set Open_dif = Workbooks("open.dif").Worksheets("open")
For Each rLTD In LTD_xls.Range("A2:A")
If IsEmpty(rLTD) Then
Exit For
End If
For Each rOPN In Open_dif.Range("A2:A")
If IsEmpty(rOPN) Then
Exit For
End If
If (rOPN = rLTD) Then
rOPN.EntireRow.Delete shift:=xlUp
End If
Next rOPN
Next rLTD
End Sub
Basicaly i have 2 sheets, this code "supposably" skans each cell in first column in Workbooks("LTD Open.xls").Worksheets("open") and matches it against Workbooks("open.dif").Worksheets("open") first column.
If identical cell cannot be found then row should be removed.
My Problem:
I get an error as soon as i get to For Each rLTD In LTD_xls.Range("A2:A")
which is the first "For". It sais: "Method "Range" of object "_Worksheet" failed". What am i doing wrong?
BTW, how can i skip one step in a loop if a value is not a number?
If i use this code:
If Not IsNumeric(rLTD) Then
Next rLTD
End If
blah blah blah...
Next rLTD
i get an error: "Next Without For" <- or something like this. What's wrong here?
Thanks!