VBA Code if this and that, then highlight both cells.

ShwetaD

New Member
Joined
Nov 18, 2022
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hi, Here's my dataset and I want to write a vba code such that

if AssetCondition="Fair" or "Fair-Good" And PlanType="Plan Type 3 - Capital Renewal" then highlight both AssetCondition and PlanType cells. I need to apply this rule to the whole sheet.

1668805958611.png
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
What line is erroring out?

If it's this line...

VBA Code:
lngRowTo = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

...it's most probably because there's no data on the tab used when setting the wsSrc variable (I used Sheet1 as an example). Ensure the tab the variable uses has some data and try again.

Not too sure beyond that I'm afraid as it works for me :confused:
 
Upvote 0
What line is erroring out?

If it's this line...

VBA Code:
lngRowTo = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

...it's most probably because there's no data on the tab used when setting the wsSrc variable (I used Sheet1 as an example). Ensure the tab the variable uses has some data and try again.

Not too sure beyond that I'm afraid as it works for me :confused:
Yes it's on that line. I renamed the tab to Sheet1. Will check for data and run it. Thanks for the prompt response.
 
Upvote 0
Isn't this a duplicate thread of this one? You should only post one thread per question.
 
Upvote 0
Isn't this a duplicate thread of this one? You should only post one thread per question.
Yes and No 🙂. It includes items 3 to 9 which I wanted to see if someone could help with. Didn't know if I could edit my question here so posted another one that is phrased to the point.
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: VBA Code for Highlighting Cells based on If then Rules
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,215,045
Messages
6,122,830
Members
449,096
Latest member
Erald

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