Help in revising VBA code

Vtookup

Board Regular
Joined
May 30, 2017
Messages
121
Office Version
  1. 2016
  2. 2013
Hi All.
Need help to revise this code.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim DestR As Range
Dim R As Long

If Not Intersect(Target, [A4:A19]) Is Nothing Then

If Target.Count > 1 Then
MsgBox "Select only one cell"
Else
R = 1
Set DestR = Range("B2:C10")
Do Until DestR(R) = "" Or R > DestR.Count
R = R + 1
Loop
If R > DestR.Count Then
MsgBox "You have reached the limit " '& DestR.Address(False, False)
Else
Application.EnableEvents = False
DestR(R).Value = Target.Value
Application.EnableEvents = True
End If
End If
End If
End Sub
now i want Set DestR = Range("B2:C10") to Set DestR = Range("A2")
every time i click anywhere on [A4:A19]
it will replace the content of A2. No more error message.
Also does this allow to extend same function to another range
like [I4:I19] to range("I2")?
Thanks in advance for the help
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I'm basing my response on this bit:
every time i click anywhere on [A4:A19]
it will replace the content of A2. No more error message.
Also does this allow to extend same function to another range
like [I4:I19] to range("I2")?
Please try the following & see if it does what you want:

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.CountLarge = 1 And Not Intersect(Me.Range("A4:A19,I4:I19"), Target) Is Nothing Then
        Application.EnableEvents = False
        If Target.Column = 1 Then [A2] = Target
        If Target.Column = 9 Then [I2] = Target
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,215,072
Messages
6,122,968
Members
449,095
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top