Double click on one cell, change background color on that cell and the adjacent

SamFunzie

New Member
Joined
Oct 4, 2021
Messages
10
Office Version
  1. 2016
Platform
  1. Windows
Hi,

First post so please bear with me... my excel vba experience is very limited, but I have worked in word vba

I want to be able to double-click on a cell and change the background fill color to red (simple enough ;)) but I also want to change the adjacent cell (column) fill to yellow. I have tried but something is just not right...

Please note, I tried this with conditional formatting and a checkbox but it was getting too bulky (different question I know).

Hear is what I have tried... again please be kind... probably a rookie error but I just can't see it...

Thanks in advance...

SF

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Set myCalendar = Range("A1:EB41")
If Target.Interior.ColorIndex = 3 Then
Target.Interior.ColorIndex = xlNone
Else
Target.Interior.ColorIndex = 3
For Each cell In myCalendar
If
cell.Interior.ColorIndex = 3 
Then 
cell.Offset(0, 1).Interior.ColorIndex = 6
End If
End If
Cancel = True
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Since what you have here is not doing what you want I ask this:
You said: I want to be able to double-click on a cell
Double click on what cell or cells?
Is it just the range("A1:EB41") ?
And now what do you want to do obviously what your doing here is not doing what you want.
 
Upvote 0
Hi MAiT,

My code was for illustration on what my latest iteration was... range is irrelevant for my question

double click on ANY cell... change background fill color to red as well changing the cell immediately to its right yellow

I am thinking that where things are confused is the use of "Target" vs "cell" to get the offset... all newish to me...
that's why I have come to the experts

Thanks for replying...

SF
 
Upvote 0
You said range is irrelevant for my question

That is not true. Without a range to work with that means if you double click on any cell in the sheet the script will run.

Range could be any cell in column B or column C or row 1
 
Upvote 0
I am not looking for a debate... simple assistance/direction on a simple question... although I appreciate your time, if you do not wish to help, please move along

double click on ANY cell... change background fill color to red as well changing the cell immediately to its right yellow

two cells, two colors
 
Upvote 0
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Modified  10/5/2021  12:15:35 AM  EDT
Cancel = True
Target.Interior.Color = vbRed
Target.Offset(, 1).Interior.Color = vbYellow
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,944
Messages
6,122,392
Members
449,081
Latest member
JAMES KECULAH

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