Referencing an inactive worksheet's cell in an active worksheet's cell during an if statement

Ruky

New Member
Joined
Sep 20, 2011
Messages
9
Hi,

I want to refer to a cell as part of my If..End if condition. I know how to do this if this cell is in the same worksheet. But how do you refer to another worksheet's cell?

Let's say I am working on worksheet 1's cell(1,1) and I want to refer to worksheet 2's cell (1,2)

Sample if statement:

if cell(1,1)=2 and worksheet 2's cell (1,2)=3 then

...

end if

Thanks,
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Try like this

Code:
If Cells(1, 1).Value = 2 And Worksheets("test.xls").Cells(1, 2).Value = 3 Then

test.xls must be open.
 
Upvote 0
Hi,

I want to run this in a loop in VBA. The worksheets are in the same workbook.

Thanks,
 
Upvote 0
Sorry, my original reply was rubbish. You would need something like

Code:
If Cells(1, 1).Value = 2 And Worksheets(i).Cells(1, 2).Value = 3 Then
 
Upvote 0
Alright, I adapted it into the code I am working on but now I have an application/object defined error (Run time error 1004). Here's the piece of my code:

For Each mycell In Range("u5:u20")
mycell.Select
text = mycell.Offset(0, -18)
If mycell.Offset(0, -19) <> "" And mycell.EntireRow.Font.ColorIndex = 3 Then
If Workbooks(1).Sheets("Refer").Range(Cells(n, 1)) = text Then

...
End If

If Workbooks(1).Sheets("Refer").Range(Cells(n, 1)) <> text Then

...
End If
End If

Next mycell
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,282
Members
452,902
Latest member
Knuddeluff

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