PLEASE HELP--- Double Click Macro Troubleshooting

Wildcats23

New Member
Joined
Dec 6, 2018
Messages
10
Hello, I'm trying to figure out a Macro so that if I click (For Example) where it says "Double Click" it will copy the Student # in "A4"(in Red) to "C9" AND copy the Date in "C1" (in Green) to "C8". What I would like this to be able to do is, if i double click anywhere in "C2:E6" it will populate the bottom cells with the Date and student number. THANK YOU!!!

[TABLE="class: outer_border, width: 500"]
<tbody>[TR]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Student #[/TD]
[TD]Name[/TD]
[TD]Jan[/TD]
[TD]Feb[/TD]
[TD]March[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]12
[/TD]
[TD]Jack[/TD]
[TD][/TD]
[TD][/TD]
[TD]
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]21[/TD]
[TD]Jill[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]32[/TD]
[TD]Sarah[/TD]
[TD]Double Click[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]42[/TD]
[TD]Chris[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]51[/TD]
[TD]Jen[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Date[/TD]
[TD]Jan[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Student #[/TD]
[TD]32
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Like this?

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)


Dim monthname As String
Dim studentno As Long


studentno = Cells(Selection.Row, 1)
monthname = Cells(1, Selection.Column)

Range("C9").Value = studentno
Range("C8").Value = monthname


End Sub
 
Last edited:
Upvote 0
You said:
populate the bottom cells



And what happens if you double click on two cells in the same column how would we enter two names in row 8 and 9
 
Upvote 0
Try this:
My script will do what you asked when you said this
What I would like this to be able to do is, if i double click anywhere in "C2:E6" it will populate the bottom cells with the Date and student number. THANK YOU!!!

This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("C2:E6")) Is Nothing Then
'Modified  12/6/2018  9:45:41 PM  EST
Cancel = True
Dim c As Long
Dim r As Long
r = Target.Row
c = Target.Column
Cells(8, c).Value = Cells(1, c).Value
Cells(9, c).Value = Cells(r, 1).Value
End If
End Sub
 
Last edited:
Upvote 0
If you plan to choose more then one student in one month you will need to send second student number to Rows 10 and 11 and so on.

So you will need this code.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("C2:E6")) Is Nothing Then
'Modified  12/6/2018  10:48:41 PM  EST
Cancel = True
Dim Lastrow As Long
Dim c As Long
Dim r As Long
r = Target.Row
c = Target.Column
Lastrow = Cells(Rows.Count, c).End(xlUp).Row + 1
If Lastrow < 8 Then Lastrow = 8
Cells(Lastrow, c).Value = Cells(1, c).Value
Cells(Lastrow + 1, c).Value = Cells(r, 1).Value
End If
End Sub
 
Upvote 0
Thank you for your reply! The macro works great the only stipulation ( I apologize I didn't make this clear) is that I'm trying to figure out a way so if i click anywhere in the range it will populate only C8 & C9. Currently it populates the date and student # in the corresponding column below.
 
Upvote 0
Your original post said doubleclick

But now you said:
figure out a way so if i click anywhere

So is it click or double click
 
Upvote 0
So assuming you mean Double Click
Try this:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("C2:E6")) Is Nothing Then
'Modified  12/7/2018  1:35:15 PM  EST
Cancel = True
Dim c As Long
Dim r As Long
r = Target.Row
c = Target.Column
Cells(8, "C").Value = Cells(1, c).Value
Cells(9, "C").Value = Cells(r, 1).Value
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,155
Members
453,021
Latest member
Justyna P

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