PC Review


Reply
Thread Tools Rate Thread

Change a Cell Ref When Clicking in another Cell

 
 
=?Utf-8?B?Q2hhZCBCb3JtYW4=?=
Guest
Posts: n/a
 
      9th May 2007
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 With Quote
 
 
 
 
JW
Guest
Posts: n/a
 
      9th May 2007
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 With Quote
 
=?Utf-8?B?Q2hhZCBCb3JtYW4=?=
Guest
Posts: n/a
 
      10th May 2007
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Beginner's] Adding a letter to a cell by clicking the cell pnumminen Microsoft Excel Programming 4 9th Mar 2009 07:03 AM
Changing Cell Color by clicking on a cell =?Utf-8?B?SkVC?= Microsoft Excel Programming 2 15th Aug 2007 01:30 PM
How do I edit a cell in Excel without clicking on the cell first? =?Utf-8?B?QWxpc2E=?= Microsoft Excel Worksheet Functions 5 2nd Apr 2007 07:15 PM
how to change cell colour by simply clicking on it lovebunny Microsoft Excel Misc 9 10th Aug 2006 07:48 PM
When double clicking on link in cell it doesn't go the cell. =?Utf-8?B?QnJpYW4=?= Microsoft Excel Misc 1 17th Jul 2006 05:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:17 AM.