Haystack & needle

Csibész

New Member
Joined
Nov 17, 2005
Messages
10
Hi...

I don't get it... perhaps somebody could explain this to me.

The macro below is to find a given value in a range. If I use the actual value in Find, there's no problem. If I try to feed same through a variable (preferred way), it bombs out.

Sooo... Where do I go wrong and more importantly, how to do this right? Thanx in advance for any enlightenment!

Regards...

Sub Macro3()
TBFound = Range("A1").Value ' say it is =50
Sheets("1").Range("b1:b10").Find(TBFound, xlValue).Select
' using 50 instead of TBFound in Find - works
' using TBFound gives error
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = TBFound
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
It's kind of hard to figure out where you are going with this. Can you tell us what you want the output to be?
 
Upvote 0
Change:
Sheets("1").Range("b1:b10").Find(TBFound, xlValue).Select
to
Sheets("1").Range("b1:b10").Find(What:=TBFound).Select

Works for me.
 
Upvote 0
To use a Var you need this syntax:


Dim Found As Range, myText$, FirstAddress$

myText = InputBox("Enter text to find")

If myText = "" Then Exit Sub

Set Found = .UsedRange.Find(what:=myText, LookIn:=xlValues, MatchCase:=False)

If Not Found Is Nothing Then
FirstAddress = Found.Address

Do

'your code to do whatever here!

Loop While Not Found Is Nothing And Found.Address <> FirstAddress
End If
 
Upvote 0
Seti: it is a numeric value...

KenCriss: I am looking-up a control value (vector) in a frequently updated column 2 that returns the corresponding value from col 3. This far I'm OK. Now, I need to find this returned value and put it in the same row but next column. This works with a constant but not with a variable.

Datsmart: Works all right up to 8 decimals, but not beyond (eg: 95.50561797 is OK, 95.505617971 bombs out). As luck has it, I have to accomodate up to 14 decimals... In Fortran I'd specify double precision to fix this. Do you have a similar trick for Excel?

Thanx guys!
 
Upvote 0
Does adding:

DIM TBFound as Double

at the beginning of your code help?
 
Upvote 0

Forum statistics

Threads
1,214,426
Messages
6,119,414
Members
448,895
Latest member
omarahmed1

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