Content of Cell clicked in another cell

S

Sandip

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
 
J

joel

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
 
G

Gord Dibben

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top