Can you have multiple Private Sub macros for same cell

riley454

Board Regular
Joined
Apr 21, 2010
Messages
52
Office Version
  1. 2010
Platform
  1. Windows
I am running the following worksheet macro that increases the value of "C" column if an A column value appears in C50 which is working fine when combined with my other macros however I want to tweak my spreadsheet by making the value in C50 also change the cell color of the column A value that appears in C50

Can I add this to my existing worksheet specific macro or does it need to be run separately.
What is the simplest way?
Any coding suggestions?


"Dim Found As Range
If Target.Address <> "$C$50" Then Exit Sub
If IsEmpty(Target) Then Exit Sub
Set Found = Range("A1:A45").Find(Range("C50").Value, LookAt:=xlWhole, MatchCase:=False)
If Not Found Is Nothing Then
Found.Offset(0, 1) = 0
Found.Offset(0, 2).Value = Found.Offset(0, 2).Value + 1
Else
MsgBox "No match found, operation cancelled", vbOKOnly
End If"
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
You could add it the the curent code and tweak your current code as follows:-
Code:
Dim Found As Range
If Target.Address <> "$C$50" or IsEmpty(Target) Then Exit Sub
Set Found = Range("A1:A45").Find(Range("C50").Value, LookAt:=xlWhole, MatchCase:=False)
If Not Found Is Nothing Then
Found.Offset(0, 1) = 0
Found.Offset(0, 2).Value = Found.Offset(0, 2).Value + 1
found.interior.colorindex=44
Else
MsgBox "No match found, operation cancelled", vbOKOnly
End If

You can change the 44 to another number to find a colour to suit yourself.
The line I've added will change the background of the cell in column A which matches whatever's in C50.
 
Upvote 0

Forum statistics

Threads
1,224,547
Messages
6,179,436
Members
452,915
Latest member
hannnahheileen

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