Shazir
Banned - Rules violations
- Joined
- Jul 28, 2020
- Messages
- 94
- Office Version
- 365
- Platform
- Windows
I have been using below code where an error is occurred when it is applied to other sheets.
Error is Object variable or With block variable not set
Can i have solution for this please.
Error is Object variable or With block variable not set
Can i have solution for this please.
VBA Code:
Sub caluematch()
Dim row1, month3, month2, month1, Rating3, Rating2, Rating1, sku As String
Dim ws As Worksheet
Dim xa, xb, xc As Integer
xa = 1
xc = Worksheets("Main").Cells(1, 5)
Sheets("Main").Range("A:A").Clear
For Each ws In Worksheets
Sheets("Main").Cells(xa, 1) = ws.Name
xa = xa + 1
Next ws
Sheets("Main").Range("A2:C8").Sort Key1:=Sheets("Main").Range("B2"), Order1:=xlAscending, Header:=xlNo
For xb = 4 To xc
month3 = Worksheets("Main").Cells(xb, 3)
month2 = Worksheets("Main").Cells(xb - 1, 3)
month1 = Worksheets("Main").Cells(xb - 2, 3)
For x = 2 To 800
If Worksheets(month3).Cells(x, 17) = "D" Then
sku = Worksheets(month3).Cells(x, 2).Text
If MatchFound(month2, sku, "D") And MatchFound(month1, sku, "D") Then
Worksheets(month3).Cells(x, 18) = "Remove"
Else
End If
Else
End If
Next x
Next xb
MsgBox ("Worksheets Updated")
End Sub
Function MatchFound(shtname, sku, val) As Boolean
MatchFound = (Worksheets(shtname).Range("b:b").Find(What:=sku, LookIn:=xlValues).Offset(0, 15) = val)
End Function