Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Condensing working code

The macro below works, but can it be simplified?

What this macro is doing is putting an "H" (for holidays) in the appropriate
cells.

Sub HolidaySelection()
Dim i As Long
Dim j As Long
Range("startpoint").Select
Range("B11:AF22").ClearContents
For i = 1 To 12
For j = 1 To 31
If
Application.WorksheetFunction.CountIf(Worksheets(" Holidays").Range("F5:F13"),
DateSerial(Range("VacYear"), i, j)) Then
ActiveCell.Offset(i, j) = "H"
End If
Next j
Next i
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Condensing working code

Your code is looping 31&12 times for 372 tiumes. My code is looping 9 times
(F5 to F13)

Sub HolidaySelection()
Dim i As Long
Dim j As Long
Dim cell as Range

for each cell in Worksheets("Holidays").Range("F5:F13")
MyMonth = Month(cell)
MyDay = Day(cell)
Range("startpoint").offset(MyMonth,MyDay) = "H"
next cell

"Brad" wrote:

The macro below works, but can it be simplified?

What this macro is doing is putting an "H" (for holidays) in the appropriate
cells.

Sub HolidaySelection()
Dim i As Long
Dim j As Long
Range("startpoint").Select
Range("B11:AF22").ClearContents
For i = 1 To 12
For j = 1 To 31
If
Application.WorksheetFunction.CountIf(Worksheets(" Holidays").Range("F5:F13"),
DateSerial(Range("VacYear"), i, j)) Then
ActiveCell.Offset(i, j) = "H"
End If
Next j
Next i
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Condensing working code

I didn't declare the variable properly

Sub HolidaySelection()
Dim MyMonth As Long
Dim MyDay As Long
Dim cell as Range

for each cell in Worksheets("Holidays").Range("F5:F13")
MyMonth = month(cell)
MyDay = day(cell)
Range("startpoint").offset(MyMonth,MyDay)
next cell

"Brad" wrote:

The macro below works, but can it be simplified?

What this macro is doing is putting an "H" (for holidays) in the appropriate
cells.

Sub HolidaySelection()
Dim i As Long
Dim j As Long
Range("startpoint").Select
Range("B11:AF22").ClearContents
For i = 1 To 12
For j = 1 To 31
If
Application.WorksheetFunction.CountIf(Worksheets(" Holidays").Range("F5:F13"),
DateSerial(Range("VacYear"), i, j)) Then
ActiveCell.Offset(i, j) = "H"
End If
Next j
Next i
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default Condensing working code

Much better - Thank you!!


"Joel" wrote:

I didn't declare the variable properly

Sub HolidaySelection()
Dim MyMonth As Long
Dim MyDay As Long
Dim cell as Range

for each cell in Worksheets("Holidays").Range("F5:F13")
MyMonth = month(cell)
MyDay = day(cell)
Range("startpoint").offset(MyMonth,MyDay)
next cell

"Brad" wrote:

The macro below works, but can it be simplified?

What this macro is doing is putting an "H" (for holidays) in the appropriate
cells.

Sub HolidaySelection()
Dim i As Long
Dim j As Long
Range("startpoint").Select
Range("B11:AF22").ClearContents
For i = 1 To 12
For j = 1 To 31
If
Application.WorksheetFunction.CountIf(Worksheets(" Holidays").Range("F5:F13"),
DateSerial(Range("VacYear"), i, j)) Then
ActiveCell.Offset(i, j) = "H"
End If
Next j
Next i
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Condensing VBA code Brad Excel Discussion (Misc queries) 3 September 9th 09 05:51 PM
Condensing Format Code baconcow Excel Programming 4 May 29th 08 04:39 PM
Condensing Code steve Excel Programming 1 August 23rd 06 08:37 PM
Need help condensing with-end with code excelnut1954 Excel Programming 2 May 1st 06 03:49 PM
Trouble Condensing Code Ikaabod Excel Programming 3 April 11th 06 09:53 PM


All times are GMT +1. The time now is 01:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"