OK, so I have this code here, which will let me know whether the info entered is new data or changes to old data and put it into the correct sheet depending on which it is.
Problem is, when I get to the if statement, when it gets to ws2= it causes the run-time error 91: Object variable or with-block variable not set
Thing is, the variable is set on line 3. Even recognises it if I change it to Ws2 and converts it to correct formatting.
Anyone have any ideas?
Cheers
Ben
Problem is, when I get to the if statement, when it gets to ws2= it causes the run-time error 91: Object variable or with-block variable not set
Thing is, the variable is set on line 3. Even recognises it if I change it to Ws2 and converts it to correct formatting.
Code:
Sub copysheetdata()
Dim custID As String
Dim ws1, ws2 As Worksheet
Dim i, j As Integer
Set ws1 = Sheets(ActiveSheet.Name)
custID = ws1.Range("D3").Value
Sheets("slcustm").Select
Columns("B:B").Select
If Selection.Find(What:=custID, after:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlWhole, _
Searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=False, searchformat:=False) Is Nothing Then
ws1.Activate
ws2 = Sheets("New")
Else
ws1.Activate
ws2 = Sheets("Changes")
End If
Anyone have any ideas?
Cheers
Ben