Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

range.value / range.text not working

Status
Not open for further replies.

y2k1981

Programmer
Aug 2, 2002
773
IE
Hi all,

I'm at my wits end here. I have the following code:

Code:
sub myDateSub()
Dim ws as worksheet
dim c as range
dim rng as range
dim cn as string ' I don't know what I should call this ?

set ws as sheets("MySheet")
set rng as ws.Range("A11:D50")

for each c in rng
  if c.value = "Dates" then ' this line is the problem
  cn.value = c.address
  msgbox(cn)
  end if
next c

In the worksheet that I'm testing this in, the text "Dates" is contained in cell A26, so the msgbox should come up as $A£26, but no such luck. The cell is formatted as general. i also tried saying c.text instead of .value but still no luck. i even tried c.value2 ... even thought I have NOOOOO idea what that does !!

please, can somebody help?

 
this worked for me

Sub myDateSub()
Dim ws As Worksheet
Dim c As Range
Dim rng As Range
Dim cn As String ' I don't know what I should call this ?

Set ws = Sheets("Sheet1")
Set rng = ws.Range("A11:D50")

For Each c In rng
If c.Value = "Dates" Then ' this line is the problem
cn = c.Address
MsgBox (cn)
End If
Next c


End Sub


Thanks Rob.[yoda]
 
Rob, how is your code different from y2k's? I don't see why y2k's code shouldn't work. Time to do some debugging - put the text "Dates" in A11 temporarily, and step through the code, see what the values of variables and properties are, and figure out what's going on...


Rob
[flowerface]
 
the only difference is

cn.value in y2k

c.value in mine,
i put dates in the range and it located it and showed it in a msgbox.

regards

Thanks Rob.[yoda]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top