Hilite or to see the row number without error ? in another worksheet

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
684
Anyone

Having two worksheets. from 1st worksheet already value has been searched. now i want to find the same value in another worksheet

when i click on chkbox1_Click i activate another sheet. works fine uptil here but
error comes "Object Variable or with Block Variable not set with the following line
wkTwoSheet.Rows(FindRow.Row).Select

Below is the code
Rich (BB code):
Private Sub chkbox1_Click()

Dim wkTwoSheet As Worksheet
Set wkTwoSheet = Worksheets(uf1.txtCoSheetName.Text)
wkTwoSheet.Activate

Dim diffRange As Range
Dim SearchRange As Range
Dim FindRow As Range

Set SearchRange = wkTwoSheet.Range("B3", Range("A65536").End(xlUp))
Set FindRow = wkTwoSheet.Range("B3").Find(what:=uf1.txtSrchVal.Text, LookIn:=xlValues, lookat:=xlWhole)

 wkTwoSheet.Rows(FindRow.Row).Select                     
'Error for the above line  ..... Rows(FindRow.Row).Select    Object Variable or with Block Variable not set   


End Sub
How to see or hilite the row number without error ?
Thankx
NimishK
 
Last edited:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Looks like a couple of mistakes in there. Where are you intending your search range to be? Column B? Column A? Or both? Then you dont use Find on the search range
 
Upvote 0
Looks like a couple of mistakes in there. Where are you intending your search range to be? Column B? Column A? Or both? Then you dont use Find on the search range

Already searched in wkOnesheet from Column B (which displays in txtSrchVal.text) and when clicking on checkbox
i want to search the same from (txtSrchVal.text) in wkTwosheet as specified in column B of wkTwoSheet and hilite or get row number.
 
Last edited:
Upvote 0
Try replacing:

Code:
Set SearchRange = wkTwoSheet.Range("B3", Range("A65536").End(xlUp))
Set FindRow = wkTwoSheet.Range("B3").Find(what:=uf1.txtSrchVal.Text, LookIn:=xlValues, lookat:=xlWhole)

with:

Code:
With wkTwoSheet
    Set searchrange = .Range(.Cells(3, "B"), .Cells(.Rows.Count, "B").End(xlUp))
    Set FindRow = searchrange.Find(what:=uf1.txtSrchVal.Text, LookIn:=xlValues, lookat:=xlWhole)
End With
 
Upvote 0
The only other thing you should then do is test that FindRow isnt nothing before using it.

Code:
If Not FindRow is Nothing Then
'etc

This will prevent further errors should the find not produce a result.
 
Upvote 0
Thank you so much for the last tip. Had read somewhere of "if not Findrow....." but didnt know for what purpose.
Now I know.

thanks
NimishK
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,276
Members
449,075
Latest member
staticfluids

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