Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Change a Cell Ref When Clicking in another Cell

I'd like to be able to change a cell reference in one cell based upon which
cell I've currently clicked in. Example. My formulas are all entered in
Sheet1. If I click in cell B1 on Sheet1, the value in cell A1 on
Sheet1refers to Sheet2!A1. If instead, I click in cell C1 on Sheet1, the
value in A1 on Sheet1 will refer to Sheet3!A1 and so on. I'm only somewhat
fluent in VBA. Any help would be appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Change a Cell Ref When Clicking in another Cell

In the Microsoft Excel Objects folder in your VBA Project, click on
Sheet1.
Using your example below, add this into Sheet1's module.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
if Target.Address = "$B$1" Then
Cells(1,1).Formula = "=Sheet2!A1"
ElseIf Target.Address = "$C$1" Then
Cells(1,1).Formula = "=Sheet3!A1"
End If
End Sub

Simply extend this same pattern for however many different scenarios
you have.

HTH
-Jeff-

Chad Borman wrote:
I'd like to be able to change a cell reference in one cell based upon which
cell I've currently clicked in. Example. My formulas are all entered in
Sheet1. If I click in cell B1 on Sheet1, the value in cell A1 on
Sheet1refers to Sheet2!A1. If instead, I click in cell C1 on Sheet1, the
value in A1 on Sheet1 will refer to Sheet3!A1 and so on. I'm only somewhat
fluent in VBA. Any help would be appreciated.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Change a Cell Ref When Clicking in another Cell

Thanks for your help, JW. It worked (with one minor change - I had to
enclose the sheet names between single quotes).

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
if Target.Address = "$B$1" Then
Cells(1,1).Formula = "='Sheet2'!A1"
ElseIf Target.Address = "$C$1" Then
Cells(1,1).Formula = "='Sheet3'!A1"
End If
End Sub

"JW" wrote:

In the Microsoft Excel Objects folder in your VBA Project, click on
Sheet1.
Using your example below, add this into Sheet1's module.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
if Target.Address = "$B$1" Then
Cells(1,1).Formula = "=Sheet2!A1"
ElseIf Target.Address = "$C$1" Then
Cells(1,1).Formula = "=Sheet3!A1"
End If
End Sub

Simply extend this same pattern for however many different scenarios
you have.

HTH
-Jeff-

Chad Borman wrote:
I'd like to be able to change a cell reference in one cell based upon which
cell I've currently clicked in. Example. My formulas are all entered in
Sheet1. If I click in cell B1 on Sheet1, the value in cell A1 on
Sheet1refers to Sheet2!A1. If instead, I click in cell C1 on Sheet1, the
value in A1 on Sheet1 will refer to Sheet3!A1 and so on. I'm only somewhat
fluent in VBA. Any help would be appreciated.



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
Add or Delete borders of a cell by clicking on that cell Happy Proby Excel Discussion (Misc queries) 1 November 8th 09 04:37 AM
How do I edit a cell in Excel without clicking on the cell first? Alisa Excel Worksheet Functions 5 April 2nd 07 07:15 PM
how to change cell colour by simply clicking on it lovebunny Excel Discussion (Misc queries) 9 August 10th 06 07:48 PM
Can I toggle the value of a cell by clicking directly on the cell? steve-o Excel Discussion (Misc queries) 3 July 17th 06 09:47 PM
Clicking Cell Link Changes Cell on Another Sheet nshah Excel Discussion (Misc queries) 1 August 31st 05 01:50 AM


All times are GMT +1. The time now is 09:23 AM.

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"