Excel VBA to compare 2 dates, evaluate cell contents, and enter value

Doug Mutzig

Board Regular
Joined
Jan 1, 2019
Messages
57
Office Version
  1. 365
Platform
  1. Windows
Good afternoon all,

I have a workbook that has several tabs. Each tab has 1 table of information, and each tab is for use by an individual unit. The table has several columns and rows of information including one column that contains dates (DEROS column), there are also columns that contain a date in the header (in text format since headers are formatted that way in tables). What I would like to happen is for each cell in a date headed column a check is done that looks to see if the cell is blank and if blank to compare the row DEROS date to the column header date and if the DEROS date is greater than the Header date enter a 1. If the cell already contains something (could be 1, 0, .5, 1*, etc.) do not overwrite.

I have a formula that I can use in the cells
Code:
=IF(DATE(YEAR($B3),MONTH($B3)<wbr>,1)>VALUE(H$2),1,"")
, however, end users will be entering numbers manually which would overwrite the formula.

I would like to use a button to manually run the script and be able to run it on any of the tabs (i.e. not set to a specific table). I believe since there is only 1 table per tab I could just have the script look at the active sheet, find the table, and run.

To make it more complected the DEROS column can have a variable amount of rows and there can also be a variable amount of date columns. I think I could get the script to go to the DEROS column and then go from the bottom up to get the last entry however I am not sure how. For the variable date columns I am at a loss.

I have added a table that hopefully shows what I am talking about.

DEROSNameSkillAug-2019Sep-2019Oct-2019Jan-2020Feb-2020
9/15/20191
12/5/2019111
4/20/202000111
2/6/20201.511

<tbody>
</tbody>


Thank you all for your help on this!
Doug
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,214,606
Messages
6,120,483
Members
448,967
Latest member
visheshkotha

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