VBA Request

DRWonoski

Board Regular
Joined
Mar 20, 2014
Messages
99
Hello Everyone,

I'm new to vba and need a little help getting certain cells formatted based on their date in number value. I basically have a large calendar displayed in row format as shown below.

EzIE9xX.png


The numbers displayed are actually number values associated with the date (ie Oct 1 is actually 41913, Oct 2 is 41914 etc)

I have list created on a different sheet (named Reference) which contains two dates per month also in Number form (41916 for example).

Is there a vba code that I can use to format the dates found in reference to display with a thick border on the calendar or better yet, to format the cells below that date in the calendar to have a thick border?

Essentially, each year I would like to just have to update that reference sheet with the new dates and have it automatically format the corresponding cell to look like the below image.

hQWCEY2.png
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try running this code in the Calendar sheet.
Dates to format in sheet "Reference" column "A"
Code:
[COLOR="Navy"]Sub[/COLOR] MG25Aug36
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] Rng = ActiveSheet.UsedRange
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
    .CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]If[/COLOR] IsDate(Dn.Value) [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Set[/COLOR] .Item(Dn.Value) = Dn
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]With[/COLOR] Sheets("Reference")
    [COLOR="Navy"]Set[/COLOR] Rng = .Range(.Range("A1"), .Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
[COLOR="Navy"]If[/COLOR] .exists(Dn.Value) [COLOR="Navy"]Then[/COLOR]
    .Item(Dn.Value).Offset(1).Borders.Weight = 4
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] With


[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Hi Mick,

Thank you for the quick response. I tested out what you said to do and unfortunately nothing happened. I tried adjusting the Range to match what I had but failed. I'm assuming it may have something to do with how I'm calling the cells in the calendar. I have attached a copy of my reference sheet so you can see the "Schedule" area which has the range, again converted to those numbers, and a copy of the formula I'm using on the calendar to create the dates. Any advice here? Thanks again

0t1HMeW.png

DOk0KRx.png
 
Upvote 0
If you could send a copy of your file using "Box.com" (free file sharing) it would be easier to work with you data, a picture means that I have to manually reconstruct your file to be able to work with it.
 
Upvote 0

Forum statistics

Threads
1,215,446
Messages
6,124,904
Members
449,194
Latest member
JayEggleton

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