Working in Sheet2 with data from Sheet1

P

Philosophaie

I am working in Sheet2. The data is in Sheet1. I can not get the data in
column in the 15th column to initalize the "If" even if Textbox1.Text matches.

For k= 1 to 100
If Sheets("Sheet1").Cells(k,15)=TextBox1.Text Then
code...
End if
Next k
 
P

Philosophaie

I tried:

If Sheets("Sheet1").Cells(k,15)=Sheets("Sheet2").TextBox1.Text Then

With Sheets("Sheet2")
If Sheets("Sheet1").Cells(k,15)=.TextBox1.Text Then
....
End With

If Sheets("Sheet1").Cells(k,15)=TextBox1.Text Then

Nothing worked.
 
G

GS

Philosophaie wrote :
I am working in Sheet2. The data is in Sheet1. I can not get the data in
column in the 15th column to initalize the "If" even if Textbox1.Text
matches.

For k= 1 to 100
If Sheets("Sheet1").Cells(k,15)=TextBox1.Text Then
code...
End if
Next k

Lots of possibilities here! What is in Cells(k, 15)? Have you tried
specifying Cells(k, 15).Text since your evaluating it against text
stored in the textbox? We need more info in order to know how to better
help you!

regards,
 
D

Dave Peterson

I'd add the property:

If Sheets("Sheet1").Cells(k,15).value = Sheets("Sheet2").TextBox1.Text Then

And maybe it's an upper/lower case difference:

if lcase(Sheets("Sheet1").Cells(k,15).value) _
= lcase(Sheets("Sheet2").TextBox1.Text) Then

If these don't help, I think you should try adding a msgbox before the line:

msgbox "***" & Sheets("Sheet1").Cells(k,15).value & "***" _
& "***" & sheets("sheet2").textbox1.text & "***"

To see if you can spot the difference.
 
P

Philosophaie

Already tried Cells(k,15).Text and .Value they did not work. I purposefully
put a number in the Textbox that exists many times in "Sheet1" row 15.
 
G

GS

Philosophaie has brought this to us :
Already tried Cells(k,15).Text and .Value they did not work. I purposefully
put a number in the Textbox that exists many times in "Sheet1" row 15.

Your code snippets work for me so I suspect that 'Not Cells(k, 15) =
TextBox1.Text' is the case. Did you check for that? I ask because I
don't see an 'Else' clause in your If construct. If for any reason VBA
determines it's not equal then you'll have something to work with
beyond just trying to figure out why '=' doesn't work.

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top