VBA Error 91: Object variable or With block variable not set

unknownymous

Board Regular
Joined
Sep 19, 2017
Messages
249
Office Version
  1. 2016
Platform
  1. Windows
Hi Guys,

I am having an VBA Error 91 using below codes and it stopped in " If none_lastrow.Row > na_lastrow.Row Then"

Thanks in advance for the help. :)

===========================

Sub NONE()



'Set conditional formatting
Set None_check_tab = Workbooks("Data Macro").Sheets("NONE Check")

Set Col = None_check_tab.Columns(2)
Col.FormatConditions.Add Type:=xlTextString, String:="_NONE", _
TextOperator:=xlContains
Col.FormatConditions.Add Type:=xlTextString, String:="N/A", _
TextOperator:=xlContains

With Col.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With

With Col.FormatConditions(2).Interior
.PatternColorIndex = xlAutomatic
.Color = 13551615
.TintAndShade = 0
End With
Col.FormatConditions(1).StopIfTrue = False




'Sort by conditional formatting
Set lrow = None_check_tab.Cells.Find(What:="*", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False)
Set fmrange = Range(Cells(4, 1), Cells(lrow.Row, 5))

None_check_tab.Sort.SortFields.Clear
None_check_tab.Sort.SortFields.Add Key:=Range( _
Cells(4, 2), Cells(lrow.Row, 2)), SortOn:=xlSortOnCellColor, order:=xlDescending, DataOption:= _
xlSortNormal
With None_check_tab.Sort
.SetRange Range(Cells(4, 1), Cells(lrow.Row, 5))
.header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With


Set none_lastrow = None_check_tab.Cells.Find(What:="_NONE", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False)

Set na_lastrow = None_check_tab.Cells.Find(What:="N/A", _
After:=Range("A1"), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False)


If none_lastrow.Row > na_lastrow.Row Then
LastRow = none_lastrow.Row
Else
LastRow = na_lastrow.Row
End If

Rows(LastRow + 1 & ":" & Rows.Count).Delete
Cells.FormatConditions.Delete




End Sub

===========================
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
You are using .Find method to find a string, but the string does not exist then the objects are empty, you must first ask if they are not empty:

If not none_lastrow is nothing then
If not na_lastrow is nothing then
If none_lastrow.Row > na_lastrow.Row then
'Your code
End if
Else
Msgbox "no exists na"
End if
Else
Msgbox "not exists none"
End if
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top