Not finding range

Moonbeam111

Board Regular
Joined
Sep 24, 2018
Messages
88
Office Version
  1. 365
  2. 2010
I'm trying to find the name in range("C21") , match it with one of the cells in the one of the cells in that list and offset from range("C21") again. But rfound keeps coming up as nothing so its exiting the sub. Is something wrong with my code? Please advise me.

VBA Code:
Dim rfound As Object
Set rfound = Sheets("Sheet1").Range("C21").Find(what:=Range("C133,C143,C153,C163,C173,C183"))
If rfound Is Nothing Then
Exit Sub
Else: rfound.Offset(5, 1) = rfound.Offset(5, 1) + 1
End If
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Maybe like:
VBA Code:
    Dim searchValue As Variant
    searchValue = Sheets("Sheet1").Range("C21").Value

    Dim searchRange As Range
    Set searchRange = Sheets("Sheet1").Range("C133,C143,C153,C163,C173,C183")

    Dim rfound      As Range
    Set rfound = searchRange.Find(What:=searchValue, LookIn:=xlValues, LookAt:=xlWhole)

    If rfound Is Nothing Then
        Exit Sub
    Else
        rfound.Offset(5, 1).Value = rfound.Offset(5, 1).Value + 1
    End If
 
Upvote 0
Thanks. Just had to make a small tweak to your code in the last line and it worked as intended.

VBA Code:
    Dim searchValue As Variant
    searchValue = Sheets("Sheet1").Range("C21").Value

    Dim searchRange As Range
    Set searchRange = Sheets("Sheet1").Range("C133,C143,C153,C163,C173,C183")

    Dim rfound      As Range
    Set rfound = searchRange.Find(What:=searchValue, LookIn:=xlValues, LookAt:=xlWhole)

    If rfound Is Nothing Then
        Exit Sub
    Else
       Range("C21").Offset(5, 1) = Range("C21").Offset(5, 1) + 1
    End If
 
Upvote 0

Forum statistics

Threads
1,226,117
Messages
6,189,068
Members
453,524
Latest member
AshJames

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