Find the Value of a Cell in the spreadsheet

tcnt9176

Board Regular
Joined
Jun 23, 2008
Messages
223
I just need to know what is wrong with this code. I am trying to have the macro find whatever is entered into cell ("CA1"). Thanks for your help!!


Code:
    Selection.Find(What:="("CA1").Value", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try this Code:

Code:
Sub display_value()

    Dim ws As Worksheet
    Dim val As Variant
    
    Set ws = ActiveWorkbook.Worksheets("Sheet2")
    val = ws.Range("CA1").Value
    
    MsgBox "The value in cell CA1 on worksheet " & ws.Name & " equals " & val
    
End Sub

I took the extra step of specifying what worksheet to look at. If you do not specify what worksheet the active worksheet is used. I think the key statement you are looking for is "Range("CA1").Value"... which will return the value entered in cell "CA1".
 
Upvote 0
I just need to know what is wrong with this code. I am trying to have the macro find whatever is entered into cell ("CA1"). Thanks for your help!!


Code:
    Selection.Find(What:="("CA1").Value", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate

How about

Code:
    Cells.Find(What:=Cells("CA1").Value, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate
 
Upvote 0
Thanks. I forgot to mention that cell ("CA1") was on another sheet. I tried the code below and got another error.
Code:
Cells.Find(What:=Cells("'Sheet1'!CA1").Value, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate
 
Last edited:
Upvote 0
Thanks. I forgot to mention that cell ("CA1") was on another sheet. I tried the code below and got another error.
Code:
Cells.Find(What:=Cells("'Sheet1'!CA1").Value, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate

The What bit should be worksheets("Sheet1").cells("CA1").value
 
Upvote 0
Create a variable and put the value of CA1 into it

x = Worksheets("OtherSheetName").Range("CA1").Value

Then use the variable in your Find statement

What := x
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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