VBA code to run a VBA code when I press a cell.

KlausW

Active Member
Joined
Sep 9, 2020
Messages
453
Office Version
  1. 2016
Platform
  1. Windows
Hi I have a challenge, I have this VBA code to run a VBA code when I press a cell.
It doesn't really work as intended, it should be like that when I click on a cell in column J, the value from column A is displayed in cell J1. Example I press J6 and the date written in A6 should appear in J1.
Any help will be appreciated
Best Regards
Klaus W

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("j2:j32")) Is Nothing Then
Range("j1").Value = Range("a2:a32").Value
End If
Call Mail
End Sub
 
It would be more common to use Target.Count = 1.
Since you are updating a value, if you also have a Worksheet_Change it will trigger that event.
If that is desirable then leave it the way it is if not then have Application.EnableEvents = False just after the IF and Application.EnableEvents = True just before the End If
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Klaus,

Didn't I already answer this for you over here yesterday?

If you did not understand something in my explanation or had a follow-up question on it, you should have continued asking/posting there.
 
Upvote 0
I have now merged the two threads together (posts 9-12 were from the new thread).
In the future, please do not post the same question in two different threads.
As per forum rules, duplicate threads will typically be locked or deleted (rule 12 here: VBA code to run a VBA code when I press a cell.)
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

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