Need help with row calcs

carrion

New Member
Joined
Dec 13, 2004
Messages
5
Hello,

I'm having a great deal of trouble for such a lame reason. Here's my problem.

I'm redoing a schedule for my work. Each row contains color coded cells to represent different shifts and different locations of the shifts. In order to tell the cells to be a certain color, I wrote a macro to automatically format cells instead of having to do them manually (which what was previously done).

Here is the code for that macro if it helps at all:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    With Range("B2:AE12")   'Active Range to apply macro to.  Range needs to be changed with additional rows/colums
        With Target
            If .Cells.Count >= 1 Then
                Select Case .Value
                    Case "l"
                        .Borders.Color = RGB(0, 0, 0)
                        .Borders.Weight = xlMedium
                        .Interior.ColorIndex = 8
                    Case "k"
                        .Borders.Color = RGB(0, 0, 0)
                        .Borders.Weight = xlMedium
                        .Interior.ColorIndex = 6
                    Case "m"
                        .Borders.Color = RGB(0, 0, 0)
                        .Borders.Weight = xlMedium
                        .Interior.ColorIndex = 10
                    Case "p"
                        .Borders.Color = RGB(0, 0, 0)
                        .Borders.Weight = xlMedium
                        .Interior.ColorIndex = 46
                    Case "r"
                        .Borders.Color = RGB(0, 0, 0)
                        .Borders.Weight = xlMedium
                        .Interior.ColorIndex = 5
                    Case "o"
                        .Borders.Color = RGB(0, 0, 0)
                        .Borders.Weight = xlMedium
                        .Interior.ColorIndex = 7
                    Case "c"
                        .Borders.Color = RGB(0, 0, 0)
                        .Borders.Weight = xlMedium
                        .Interior.ColorIndex = 16
                    Case Else
                        Selection.ClearFormats
                End Select
            End If
        End With
    End With
End Sub

Now I need to add the total hours for the day at the end of the row. I want to be able to make a macro that will calculate the total hours at the end of each row based on whether there is one of the "case" letters from above in the cell. I don't want to include cells with a "c" counted towards the total hours because those are hours that us student workers have claimed to have classes on (...claimed lol) so working would be impossible.

I hope I got what I was thinking across and hopefully someone can have to answer I'm looking for. Let me know if I left anything unexplained. Thanks for any help you can give me.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Hi carrion,

This is a bit confusing. First, you mention a range to apply the macro to as

With Range("B2:AE12")

but this statement is totally inactive as it is because it is immediately overridden by the next With Target statement. If you intend the routine to ignore Targets (changes) outside this range the statement should be

If Intersect(Target,Range("B2:AE12")) Is Nothing Then Exit Sub

and of course the corresponding End With should be deleted.

Regarding adding the total hours at the end of the row, it is not clear whether you want to total columns containing hours in this row and put the result at the end of the row, and where the end of the row is. Is it a particular column, or just the first empty cell in the row? Also, are there other columns other than the one the user is entering a letter (such as "c") into that do not contain hours or that should not be included in the total?

Damon
 
Upvote 0

Forum statistics

Threads
1,202,908
Messages
6,052,488
Members
444,587
Latest member
ezza59

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