Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 208
Default Cell Reference on a different sheet

I'm trying to use this code

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyCell As String
'Change callout here as desired
MyCell = "Z1"

If Range(MyCell).ValueThen
Exit Sub
Else
MsgBox "Please use a value of ""P"" or ""F"" in appropriate cells!", ,
"Invalid Entry"

End If
End Sub

Which works fine if Z1 is on the current sheet (Sheet 1). But I want to
reference a cell on a different sheet (Sheet 3) in the same workbook. How do
I do this?

MyCell = "Sheet3!Z1"
MyCell = "'Sheet3!'Z1"
doesn't work...

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Cell Reference on a different sheet

MycellVal = Sheets(Sheet1).Range("A1")
OR
MycellVal = Sheets(Sheet1).Cells(1,1)
OR
MycellVal = Sheets(<Sheetindex).Range("A1")


If this post helps click Yes
---------------
Jacob Skaria


"Bishop" wrote:

I'm trying to use this code

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyCell As String
'Change callout here as desired
MyCell = "Z1"

If Range(MyCell).ValueThen
Exit Sub
Else
MsgBox "Please use a value of ""P"" or ""F"" in appropriate cells!", ,
"Invalid Entry"

End If
End Sub

Which works fine if Z1 is on the current sheet (Sheet 1). But I want to
reference a cell on a different sheet (Sheet 3) in the same workbook. How do
I do this?

MyCell = "Sheet3!Z1"
MyCell = "'Sheet3!'Z1"
doesn't work...

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 208
Default Cell Reference on a different sheet

Now I'm getting Error: Type Mismatch. Do I have to change Dim...String?

"Jacob Skaria" wrote:

MycellVal = Sheets(Sheet1).Range("A1")
OR
MycellVal = Sheets(Sheet1).Cells(1,1)
OR
MycellVal = Sheets(<Sheetindex).Range("A1")


If this post helps click Yes
---------------
Jacob Skaria


"Bishop" wrote:

I'm trying to use this code

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyCell As String
'Change callout here as desired
MyCell = "Z1"

If Range(MyCell).ValueThen
Exit Sub
Else
MsgBox "Please use a value of ""P"" or ""F"" in appropriate cells!", ,
"Invalid Entry"

End If
End Sub

Which works fine if Z1 is on the current sheet (Sheet 1). But I want to
reference a cell on a different sheet (Sheet 3) in the same workbook. How do
I do this?

MyCell = "Sheet3!Z1"
MyCell = "'Sheet3!'Z1"
doesn't work...

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Cell Reference on a different sheet

Try the below. Please change the workbook name and the sheet name accordingly

Dim strValue As String

strValue = Workbooks("Book5").Sheets("Sheet1").Range("A1")
strValue = ActiveSheet.Range("A1")
strValue = ActiveSheet.Cells(1, 1)



If this post helps click Yes
---------------
Jacob Skaria


"Bishop" wrote:

Now I'm getting Error: Type Mismatch. Do I have to change Dim...String?

"Jacob Skaria" wrote:

MycellVal = Sheets(Sheet1).Range("A1")
OR
MycellVal = Sheets(Sheet1).Cells(1,1)
OR
MycellVal = Sheets(<Sheetindex).Range("A1")


If this post helps click Yes
---------------
Jacob Skaria


"Bishop" wrote:

I'm trying to use this code

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyCell As String
'Change callout here as desired
MyCell = "Z1"

If Range(MyCell).ValueThen
Exit Sub
Else
MsgBox "Please use a value of ""P"" or ""F"" in appropriate cells!", ,
"Invalid Entry"

End If
End Sub

Which works fine if Z1 is on the current sheet (Sheet 1). But I want to
reference a cell on a different sheet (Sheet 3) in the same workbook. How do
I do this?

MyCell = "Sheet3!Z1"
MyCell = "'Sheet3!'Z1"
doesn't work...

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 208
Default Cell Reference on a different sheet

Now I'm getting Run-time Error: '1004' Method 'Range' of object '_Worksheet'
failed. Here's exactly what I have for code in Book 2 Sheet1:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyCell As String
'Change callout here as desired
'MyCell = "G1"
MyCell = Workbooks("Book2").Sheets("Sheet3").Range("G1")

If Range(MyCell).Value Then
Exit Sub
Else
MsgBox "Please use a value of ""P"" or ""F"" in appropriate cells!", ,
"Invalid Entry"

End If
End Sub

In Book2 Sheet3 is this formula: =COUNTA(Sheet1!A1:E5)=25

So frustrating... what am I doing wrong?

"Jacob Skaria" wrote:

Try the below. Please change the workbook name and the sheet name accordingly

Dim strValue As String

strValue = Workbooks("Book5").Sheets("Sheet1").Range("A1")
strValue = ActiveSheet.Range("A1")
strValue = ActiveSheet.Cells(1, 1)



If this post helps click Yes
---------------
Jacob Skaria


"Bishop" wrote:

Now I'm getting Error: Type Mismatch. Do I have to change Dim...String?

"Jacob Skaria" wrote:

MycellVal = Sheets(Sheet1).Range("A1")
OR
MycellVal = Sheets(Sheet1).Cells(1,1)
OR
MycellVal = Sheets(<Sheetindex).Range("A1")


If this post helps click Yes
---------------
Jacob Skaria


"Bishop" wrote:

I'm trying to use this code

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyCell As String
'Change callout here as desired
MyCell = "Z1"

If Range(MyCell).ValueThen
Exit Sub
Else
MsgBox "Please use a value of ""P"" or ""F"" in appropriate cells!", ,
"Invalid Entry"

End If
End Sub

Which works fine if Z1 is on the current sheet (Sheet 1). But I want to
reference a cell on a different sheet (Sheet 3) in the same workbook. How do
I do this?

MyCell = "Sheet3!Z1"
MyCell = "'Sheet3!'Z1"
doesn't work...



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Cell Reference on a different sheet

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim MyCell As Range
set mycell = ThisWorkbook.worksheets("Sheet 3").range("Z1")

if mycell.value = "something" then
'do something
else
'do something else
End If

End Sub

But I don't understand why you'd be checking the value on a different sheet when
you change the selection on this sheet?????


Bishop wrote:

I'm trying to use this code

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyCell As String
'Change callout here as desired
MyCell = "Z1"

If Range(MyCell).ValueThen
Exit Sub
Else
MsgBox "Please use a value of ""P"" or ""F"" in appropriate cells!", ,
"Invalid Entry"

End If
End Sub

Which works fine if Z1 is on the current sheet (Sheet 1). But I want to
reference a cell on a different sheet (Sheet 3) in the same workbook. How do
I do this?

MyCell = "Sheet3!Z1"
MyCell = "'Sheet3!'Z1"
doesn't work...


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nesting a sheet name reference within a cell reference??? Broyston Excel Discussion (Misc queries) 9 July 8th 08 08:35 PM
multiple cell reference from sheet to sheet KMR R.A. Excel Worksheet Functions 0 May 29th 08 12:48 AM
Changing sheet reference to cell reference TeeJay Excel Worksheet Functions 3 October 19th 07 11:50 AM
Cell to reference sheet tab name Uggles Excel Discussion (Misc queries) 1 July 6th 07 04:22 AM
Is is possible for a cell to reference it's "sheet name"? kjbrr Excel Worksheet Functions 1 June 3rd 05 09:35 PM


All times are GMT +1. The time now is 12:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"