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.

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]DEROS[/TD]
[TD]Name[/TD]
[TD]Skill[/TD]
[TD]Aug-2019[/TD]
[TD]Sep-2019[/TD]
[TD]Oct-2019[/TD]
[TD]Jan-2020[/TD]
[TD]Feb-2020[/TD]
[/TR]
[TR]
[TD]9/15/2019[/TD]
[TD][/TD]
[TD][/TD]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]12/5/2019[/TD]
[TD][/TD]
[TD][/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4/20/2020[/TD]
[TD][/TD]
[TD][/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]2/6/2020[/TD]
[TD][/TD]
[TD][/TD]
[TD]1[/TD]
[TD].5[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


Thank you all for your help on this!
Doug
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,224,828
Messages
6,181,217
Members
453,024
Latest member
Wingit77

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