Finding Date(s) in a Column in Order to Label Report as Either Single Date or Date Range

FrenchCelt

Board Regular
Joined
May 22, 2018
Messages
214
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a report that would either cover a single day, a week, or a 4-week range. The date(s) are displayed in Column D of my report and what I want to do is to label the cell in F2 the single date or have the date range in F2 and G2 depending on what is found in Column D in a macro.

So for example, if it only finds one date in Column D, I would like that date to be copied into F2.

If it finds a range of seven days, I would like cell L1 to say Weekly Productivity and the earliest date to be copied into F2 and the latest date into G2.

If it finds a range of 28 days, I would like cell L1 to say 4-Week Rolling Report and the earliest date to be copied into F2 and the latest date into G2.

Any help would be appreciated.
 
I've had other macros that change the sheet name and then refer to that sheet name later on in the code with no issues. And Export is the name of the sheet upon opening the file after exporting from Power BI to Excel. I checked for spaces before and after the text.
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
You've probably used the CODENAME of the sheet instead of the visible sheet name.

Try
VBA Code:
Set ws = Sheet1 ' Change to your actual code name
 
Upvote 0
Also, make sure you place the code in the right workbook (if you have multiple open).
 
Upvote 0
You've probably used the CODENAME of the sheet instead of the visible sheet name.

Try
VBA Code:
Set ws = Sheet1 ' Change to your actual code name

The code wouldn't execute using that (I changed Export to Report on the worksheet and Sheet1 to Report in the code), but I tried this and didn't get an error message:

VBA Code:
Set ws = Sheets("Report")

However, nothing happened after I ran the rest.
 
Upvote 0
The code wouldn't execute using that (I changed Export to Report on the worksheet and Sheet1 to Report in the code), but I tried this and didn't get an error message:

VBA Code:
Set ws = Sheets("Report")

However, nothing happened after I ran the rest.
Can you share your workbook via DropBox (without any sensitive info)?
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,215
Members
452,618
Latest member
Tam84

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