Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello,
I have the following code to define a range based on month which is sorted date wise. is there a way to avoid repeating the code 12 times for all months? also if there is no dates for a specific month say for november to avoid causing an error while selecting the range since the range will be empty? Thanks Dim iStart As Long Dim iEnd As Long Dim Rng As Range iStart = _ Sheets("Daily").Evaluate("=MIN(IF(MONTH(DlyAll)=1, ROW(DlyAll)))") iEnd = Sheets("Daily").Evaluate("=MAX(IF(MONTH(DlyAll)=1, ROW(DlyAll)))") Set Rng = Range("A" & iStart & ":A" & iEnd) Rng.Name = "rngJan" iStart = _ Sheets("Daily").Evaluate("=MIN(IF(MONTH(DlyAll)=2, ROW(DlyAll)))") iEnd = Sheets("Daily").Evaluate("=MAX(IF(MONTH(DlyAll)=2, ROW(DlyAll)))") Set Rng = Range("A" & iStart & ":A" & iEnd) Rng.Name = "rngFeb" iStart = _ Sheets("Daily").Evaluate("=MIN(IF(MONTH(DlyAll)=3, ROW(DlyAll)))") iEnd = Sheets("Daily").Evaluate("=MAX(IF(MONTH(DlyAll)=3, ROW(DlyAll)))") Set Rng = Range("A" & iStart & ":A" & iEnd) Rng.Name = "rngMar" |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Can I simplify a VB code?????? | Excel Discussion (Misc queries) | |||
Simplify code | Excel Worksheet Functions | |||
Need to simplify code | Excel Discussion (Misc queries) | |||
Simplify this code | Excel Programming | |||
simplify code | Excel Discussion (Misc queries) |