WeekdayName instead of Select Case

markkeith

New Member
Joined
Sep 8, 2020
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Is it possible to simplify the Select Case method
VBA Code:
Select Case Weekday(Range("startDate"), vbMonday)
    Case 1
     Range("week").ClearContents
     Range("mon").Formula2 = "=IF(ISBLANK(startDate),"""",SEQUENCE(1,days,startDate,1))"
    Case 2
     Range("week").ClearContents
     Range("tue").Formula2 = "=IF(ISBLANK(startDate),"""",SEQUENCE(1,days,startDate,1))"
    Case 3
     Range("week").ClearContents
     Range("wed").Formula2 = "=IF(ISBLANK(startDate),"""",SEQUENCE(1,days,startDate,1))"
    Case 4
     Range("week").ClearContents
     Range("thu").Formula2 = "=IF(ISBLANK(startDate),"""",SEQUENCE(1,days,startDate,1))"
    Case 5
     Range("week").ClearContents
     Range("fri").Formula2 = "=IF(ISBLANK(startDate),"""",SEQUENCE(1,days,startDate,1))"
    Case 6
     Range("week").ClearContents
     Range("sat").Formula2 = "=IF(ISBLANK(startDate),"""",SEQUENCE(1,days,startDate,1))"
    Case 7
     Range("week").ClearContents
     Range("sun").Formula2 = "=IF(ISBLANK(startDate),"""",SEQUENCE(1,days,startDate,1))"
   End Select

with WeekdayName function?
VBA Code:
Range("week").ClearContents
Range(WeekdayName(Weekday(StartDate, 2), 1, 2)).Formula2 = "=IF(ISBLANK(startDate),"""",SEQUENCE(1,days,startDate,1))"

I'm getting the same result even I choose different date.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Is "StartDate" meant to be the named range or a variable?
 
Upvote 0
Is "StartDate" meant to be the named range or a variable?
Hi @Fluff thank you for the follow-up question, Startdate is a named range where I input the date. There are also named range (mon-sun) that I want the formula to be populated once I type in the date.
 
Upvote 0
In that case you need to refer to the range like
VBA Code:
Range(WeekdayName(Weekday(Range("StartDate"), 2), 1, 2)).Formula2 = "=IF(ISBLANK(startDate),"""",SEQUENCE(1,days,startDate,1))"
 
Upvote 0
Solution
In that case you need to refer to the range like
VBA Code:
Range(WeekdayName(Weekday(Range("StartDate"), 2), 1, 2)).Formula2 = "=IF(ISBLANK(startDate),"""",SEQUENCE(1,days,startDate,1))"
Thank you so much @Fluff, it works perfectly now.
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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