Comparison of Columns VBA

Finalfight40

Active Member
Joined
Apr 24, 2018
Messages
273
Office Version
  1. 365
Platform
  1. Windows
Hi All

I am working on some vba and i haven't got to the point where i will need this yet but i know it will be useful.

I am looking to compare 2 columns lets say A and B where they contain values (Not empty) and the length of the columns are always different. (A and B will be the same length as each other)

The data would start in A2 and B2. If A2 is less than B2 it would format the cell Red.

I know i can do it with a do until isempty(activecell) loop but i know that will be very long and not the most efficient way.

Thanks
 
Last edited:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
It would be a macro for someone else to use once they get some raw data. They just want to press a button and it does everything for them basically.
 
Upvote 0
Just create a Macro to set up Conditional Formatting to do that on the whole range. No loops required.
You can get a lot of the code you need for that by recording yourself setting up Conditional Formatting to do that.
You would just need to generalize the data range to account for an unknown number of rows, but that isn't hard to do.

For example, to find the last row with data in column A, you could use this:
Code:
Dim lastRow as Long
lastRow = Cells(Rows.Count,"A").End(xlUp).Row
 
Last edited:
Upvote 0
Just create a Macro to set up Conditional Formatting to do that on the whole range. No loops required.

Ooo that would work, thanks Joe4.

Also if that is what you were trying to explain to me Johnny, sorry but i misunderstood.
 
Upvote 0

Forum statistics

Threads
1,223,954
Messages
6,175,601
Members
452,658
Latest member
GStorm

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