referencing cell via another cell

  • Thread starter Thread starter ll
  • Start date Start date
L

ll

I'm currently working on referencing a cell in anther sheet which
contins the value I need for comparison.

In other words, Cell A1 on Sheet 1 is equal to Sheet 2, Cell A15. In
my VBA code, I am needing to refer to Cell A1 of Sheet 1 to find the
value of the cell to which it refers. Is this possible?


Thanks
Louis
 
If Sheet1 cell A1 contains:

=Sheet2!A15

then in VBA

Sub qwerty()
x = Sheets("Sheet1").Range("A1").Value
MsgBox (x)
End Sub

will display the value in Sheet1 cell A1 (which is also the value in Sheet2
cell A15)
 
Worksheets("Sheet1").Range("A1").Value


Thanks for your help. Here is what I have so far. This is code in a
UserForm and I am wanting it to look at values on the active worksheet
and compare them with a textbox value (as in the code). The value is
not getting put into the cell in the timesheet, and my test msgbox
comes back blank as well. Thanks for any help you can provide. -
Louis
-----------------------------------------------------------

Private Sub CmdEnter_Click()

Dim a As Integer
Dim b As Integer
Dim testFromCell As String

For a = 9 To 300

If Worksheets("Hourly Timesheets").Cells(a, 1).Value = TextBox2.Value
Then
Worksheets("Hourly Timesheets").Cells(a, b).Select
Worksheets("Hourly Timesheets").Cells(a, b).Value = TextBox1.Value
testFromCell = worksheets("Hourly Timesheets").Cells(a, b).Value

End If
Next a

Unload Me
MsgBox testFromCell


End Sub
 
Oops - here's the missing code - b is set to the ListIndex of the
combo box:

b = Me.CboLeaveType2.ListIndex



The odd thing is that I can have text (i.e. "car 4") on sheet2 and
have a cell in sheet1 reference it, but when I try doing a date from
sheet2 (or sheet1) and comparing it to the date in my textbox, the
code runs without error but produces no result.
 
The information in the textbox is, I believe, being treated as text which is
not equal to a numeric date value.

try:
CDate(Me.TextBox1.Value) to convert the text date to numeric value.
 
The information in the textbox is, I believe, being treated as text which is
not equal to a numeric date value.

try:
CDate(Me.TextBox1.Value) to convert the text date to numeric value.



Many thanks - that did the trick!
 

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

Back
Top