vba object variable or with block variable not set (How to move on???)

MrMarcAnthony

New Member
Joined
Jun 17, 2016
Messages
6
Hello, I'm only trying to have the macro move on to the next (Selection.Find) if no value is found instead of crashing

Please help.

thank you!

Sheets("Funded Bankwide").Select
Columns("A:A").Select
Selection.Find(What:="Inside Sales", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Rows(ActiveCell.Row).Select
Selection.RowHeight = 18
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Font.Bold = True
With Selection.Font
.Name = "ARIAL"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.Color = -16777216
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With Selection.Font
.Color = -65536
.TintAndShade = 0
End With
Columns("A:A").Select
Selection.Find(What:="Others", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Can you explain in words what you are trying to do? Be as detailed as possible.
 
Upvote 0
of course

When I run the macro and it doesn't find "Inside Sales" ... it crashes and shows this error message (VBA object variable or with block variable not set.
then I have to debug it buy stepping into the macro at the next Select.find which is "Others". I would like for the macro to just move on to the next Select.find automatically.

thx
 
Upvote 0
Do you want to find every occurrence of "Inside Sales" and "Others"? If so, what do you want to do when you find them?
 
Upvote 0
thanks mumps...

Both Inside Sales & Others will only occur once in my data set in (A:A) I would like for the macro to move on if " String Text" isn't located
 
Upvote 0
Try:
Code:
Sub Test()
    Application.ScreenUpdating = False
    Dim myArray As Variant, i As Long, val As Range
    myArray = Array("Inside Sales", "Others")
    For i = LBound(myArray) To UBound(myArray)
        Set val = Sheets("Funded Bankwide").Range("A:A").Find(myArray(i), LookIn:=xlValues, lookat:=xlWhole)
        If Not val Is Nothing Then
            With val
                .RowHeight = 18
                .HorizontalAlignment = xlGeneral
                .VerticalAlignment = xlCenter
            End With
            With val.Font
                .Bold = True
                .Name = "ARIAL"
                .Size = 12
                .Color = -65536
            End With
        End If
    Next i
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
You are very welcome. :) Please let me know if it works for you.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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