Need help altering VBA

Toonies

Board Regular
Joined
Jun 8, 2009
Messages
236
Hi I am trying to alter the following VBA code that I found in this forum
http://www.mrexcel.com/forum/showthread.php?t=539877&highlight=holiday+planner

What I am trying to do is the following

I input the employees contracted daily hours in worksheet("Hours") by day, Month for the full year, I then this populate to each monthly planner using the following formula C6 =IF(ISBLANK(Hours!C6),"",Hours!C6) etc.

the full range is C6:AG31

I am trying to amend the following VBA to highlight only ( insert interior.color) the cells that have been populated with numbers from the "Hours" worksheet and ignore the Blank cells.

Code:
Private Sub CommandButton1_Click()
Dim Rng As Range, Dn As Range
Dim sDt As Date
Dim eDt As Date
Dim Ac As Integer
Dim col As Integer
Set Rng = Range(Range("B5"), Range("B" & Rows.Count).End(xlUp))
sDt = ComboBox1
eDt = ComboBox2
 Select Case True
    Case Is = holidayButton1: col = 43
    Case Is = sickLeaveButton3: col = 53
    Case Is = otherOptionButton4: col = 37
 End Select
 For Each Dn In Rng
        If Dn = nameBox1 Then
            For Ac = 1 To 31 ' Change to 31
           If Weekday(Cells(4, Ac + 2), vbMonday) < 6 Then
                If Cells(4, Ac + 2) >= sDt And Cells(4, Ac + 2) <= eDt Then
                   Dn.Offset(, Ac).Interior.ColorIndex = col
                End If
                End If
            Next Ac
        End If
    Next Dn
  Unload Me
End Sub

Is this Possible

I look forward to any replies
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hello there

Why don't you use conditional formatting in the Excel sheet rather than in VBA?
 
Upvote 0
Perhaps (I'm far from sure since there are already other IF's in the code, which could have a similar effect):

Rich (BB code):
Private Sub CommandButton1_Click()
Dim Rng As Range, Dn As Range
Dim sDt As Date
Dim eDt As Date
Dim Ac As Integer
Dim col As Integer
Set Rng = Range(Range("B5"), Range("B" & Rows.Count).End(xlUp))
sDt = ComboBox1
eDt = ComboBox2
 Select Case True
    Case Is = holidayButton1: col = 43
    Case Is = sickLeaveButton3: col = 53
    Case Is = otherOptionButton4: col = 37
 End Select
 For Each Dn In Rng
        If Dn = nameBox1 Then
            For Ac = 1 To 31 ' Change to 31
           If Cells(4, Ac + 2).Value <> "" Then
           If Weekday(Cells(4, Ac + 2), vbMonday) < 6 Then
                If Cells(4, Ac + 2) >= sDt And Cells(4, Ac + 2) <= eDt Then
                   Dn.Offset(, Ac).Interior.ColorIndex = col
                End If
                End If
                End If
            Next Ac
        End If
    Next Dn
  Unload Me
End Sub
 
Upvote 0
Hi I have tried your suggestion it blanks the weekend cells even when they have numbers in but not the other blank cells
 
Upvote 0
Try:

Rich (BB code):
Private Sub CommandButton1_Click()
Dim Rng As Range, Dn As Range
Dim sDt As Date
Dim eDt As Date
Dim Ac As Integer
Dim col As Integer
Set Rng = Range(Range("B5"), Range("B" & Rows.Count).End(xlUp))
sDt = ComboBox1
eDt = ComboBox2
 Select Case True
    Case Is = holidayButton1: col = 43
    Case Is = sickLeaveButton3: col = 53
    Case Is = otherOptionButton4: col = 37
 End Select
 For Each Dn In Rng
        If Dn = nameBox1 Then
            For Ac = 1 To 31 ' Change to 31
           If Weekday(Cells(4, Ac + 2), vbMonday) < 6 Then
                If Cells(4, Ac + 2) >= sDt And Cells(4, Ac + 2) <= eDt Then
                If Dn.Offset(, Ac).Value <> "" Then
                   Dn.Offset(, Ac).Interior.ColorIndex = col
                End If
                End If
                End If
            Next Ac
        End If
    Next Dn
  Unload Me
End Sub
 
Upvote 0
Hi Wigi

your a "STAR"
icon14.gif
icon14.gif
icon14.gif


it worked a treat

I had been trying to figure this one out for a few days

Many thanks again
:beerchug:
Toonies
 
Upvote 0

Forum statistics

Threads
1,224,537
Messages
6,179,405
Members
452,911
Latest member
a_barila

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