Combine two VBA one sheet

tanyak37

New Member
Joined
Jul 27, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
  2. Web
New to VBA - I have the code for two formulas , however I'd like to have them merged for a bingo template if anybody could please help with the code. A brief description of what im trying to achieve.
The first code - when i double click on a cell the background of the cell turns white.
Second code - when i double click on that cell that has turned white the number in that cell copies to another cell.
Thanks, below are the two formulas i'am hoping to merge.

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Target.Interior.Color = vbWhite
End Sub
VBA Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    Target.Interior.Color = vbGreen
End Sub
VBA Code:
Private Sub Worksheet_AfterDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("A4:I14")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Range("J4").Value = Target.Value
End If
End Sub


VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("A4:I14")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Range("J4").Value = Target.Value
End If
End Sub
 
Last edited by a moderator:

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi & welcome to MrExcel.
How about
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("A4:I14")) Is Nothing Then
   Cancel = True
   If Target.Interior.Color = vbWhite Then
      Range("J4").Value = Target.Value
   Else
      Target.Interior.Color = vbWhite
   End If
End If
End Sub
 
Upvote 0
Solution
Thanks, but I've got the double click change colour working, i need the cell to also copy and paste using the last vbn code posted. Merge two formulas to do 2 tasks on the same sheet same double click

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("A4:I14")) Is Nothing Then
Cancel = True
If Target.Interior.Color = vbWhite Then
Range("J4").Value = Target.Value
Else
Target.Interior.Color = vbWhite
End If
End If
End Sub


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("A4:I14")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Range("J4").Value = Target.Value
End If
End Sub
 
Upvote 0
Note that I edited your original post and put code tags around each section of your code.
Please use these code tags when posting your code (especially if posting a lot of code or multiple procedures).
It makes it much easier for us to read.

Here are instructions on how to do that: How to Post Your VBA Code
 
Upvote 0
If the code does not do what you want, then you will need to explain what you want, rather than just posting two bits of code & letting us guess. ;)
 
Upvote 0
My apologies , but ive got it going - thanks again for you help :)
 
Upvote 0
Glad it's sorted & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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