PC Review


Reply
Thread Tools Rate Thread

Content of Cell clicked in another cell

 
 
Sandip
Guest
Posts: n/a
 
      23rd Mar 2009
Hi,

I have the following macro which is not working completely as
required.

I want the macro to look into a range C18 to C45 and push the content
of the cell into C13. Incase any other cell is clicked, the macro
should not perform any action.

However the below macro selects all the cells on the sheet when click
instead of the cells within the C18:C45 range.

Can anyone advise improvement to the below macro

Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rng As Range
Set rng = Range("C18:C45")
For Each cell In rng
Range("c13").Value = ActiveCell.Value
Next
End Sub
 
Reply With Quote
 
 
 
 
joel
Guest
Posts: n/a
 
      23rd Mar 2009
You need to check against target. If you copy more than one cell into the
range c18:c45 which value do you want to be put into c13? Should c13 be more
than one location?

Sub Worksheet_SelectionChange(ByVal Target As Range)
For Each cell In target
if application.intersect(cell,Range("C18:C45")) then
Range("c13").Value = cell.Value
end if
Next cell
End Sub

"Sandip" wrote:

> Hi,
>
> I have the following macro which is not working completely as
> required.
>
> I want the macro to look into a range C18 to C45 and push the content
> of the cell into C13. Incase any other cell is clicked, the macro
> should not perform any action.
>
> However the below macro selects all the cells on the sheet when click
> instead of the cells within the C18:C45 range.
>
> Can anyone advise improvement to the below macro
>
> Sub Worksheet_SelectionChange(ByVal Target As Range)
> Dim rng As Range
> Set rng = Range("C18:C45")
> For Each cell In rng
> Range("c13").Value = ActiveCell.Value
> Next
> End Sub
>

 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      23rd Mar 2009
Sub Worksheet_SelectionChange(ByVal Target As Range)
Const WS_RANGE As String = "c18:c45"
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Me.Range("c13").Value = Target.Value
End With
End If
End Sub


Gord Dibben MS Excel MVP

On Mon, 23 Mar 2009 06:10:37 -0700 (PDT), Sandip <(E-Mail Removed)>
wrote:

>Hi,
>
>I have the following macro which is not working completely as
>required.
>
>I want the macro to look into a range C18 to C45 and push the content
>of the cell into C13. Incase any other cell is clicked, the macro
>should not perform any action.
>
>However the below macro selects all the cells on the sheet when click
>instead of the cells within the C18:C45 range.
>
>Can anyone advise improvement to the below macro
>
>Sub Worksheet_SelectionChange(ByVal Target As Range)
>Dim rng As Range
>Set rng = Range("C18:C45")
> For Each cell In rng
> Range("c13").Value = ActiveCell.Value
> Next
>End Sub


 
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
Change cell font color when cell is clicked aileen Microsoft Excel Programming 9 27th Apr 2010 08:53 PM
How to click on a cell and have the content of the cell display in a different cell marin_michael@yahoo.ca Microsoft Excel Worksheet Functions 0 6th Jun 2006 03:05 PM
Cell content of a cell based on the active Cell MIchel Khennafi Microsoft Access Macros 1 16th May 2006 06:25 AM
Cell Formula reference to cell Based On third Cell Content =?Utf-8?B?R2FicmllbA==?= Microsoft Excel Misc 1 11th Feb 2005 06:36 AM
Cell Formula reference to cell Based On third Cell Content =?Utf-8?B?R2FicmllbA==?= Microsoft Excel Misc 0 11th Feb 2005 05:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:21 PM.