Excel Macro Search Debug Error

  • Thread starter Thread starter Legacy 185509
  • Start date Start date
L

Legacy 185509

Guest
I am using a button and using search to search for term "Resize to show all values" currently it is searching for term and selecting it, but if it is not found it shows me debug error
please help me fix this error, if result is not found I want it do nothing may be if result is not found select cell A1 or something like that here is my code
Code:
Private Sub CommandButton2_Click()
Range("C1").Select
Cells.Find(What:="resize to show all values", After:=ActiveCell, LookIn:= _
        xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext _
        , MatchCase:=False, SearchFormat:=False).Activate

End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Here is one way:

Code:
Sub test()
On Error Resume Next
Cells.Find(What:="resize to show all values", After:=ActiveCell, LookIn:= _
        xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext _
        , MatchCase:=False, SearchFormat:=False).Activate
On Error GoTo 0

End Sub
 
Upvote 0
What do you want the macro to do after it selects the cell with that value?

after that button finds the result and it will select the cell and automatically it will open a bar on right side in that bar I have to manually click ok for "Resize to show all values" to generate/fetch data.
can you suggest any better way to do this?
check out this picture
for J25 it use to show "Resize to show all values" and I manually clicked ok or apply on right bar
259dd82.jpg
 
Upvote 0
Something like
Code:
Dim foundCell as Range

Set foundCell = Cells.Find(...)

If Not foundCell Is Nothing Then
    Rem do Stuff
End If
 
Upvote 0
Here is one way:

Code:
Sub test()
On Error Resume Next
Cells.Find(What:="resize to show all values", After:=ActiveCell, LookIn:= _
        xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext _
        , MatchCase:=False, SearchFormat:=False).Activate
On Error GoTo 0

End Sub

that works but instead of 0... meaning this is going on top of the row/column all the time, can it go to column A or somewhere in column it because I have to click A19 every click
 
Upvote 0
Use mikerickson's solution...much better.

For what it's worth, mine doesn't go to 0 (a spreadsheet location) it turns error checking back on.
 
Upvote 0

Forum statistics

Threads
1,224,589
Messages
6,179,744
Members
452,940
Latest member
rootytrip

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