Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

intro vba course

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Intro VBA course - select case code

Intro VBA course - select case code

ResolvedVersion 2010

James has attended:
Excel VBA Introduction course

Intro VBA course - select case code

Hi

Can you please send me the code for the EmployeeTimes spreadsheet that I used on Wednesday, I'm having trouble getting select case to work.

Thanks

James

RE: Intro VBA course - select case code

Hi James,

Thank you for your post. Here is the solution code for both parts of the Employee Times exercise:

Sub HoursWorked()

Range("G2").Select

Do Until ActiveCell.Offset(0, -5) = "" ' Until EmployeeID empty

ActiveCell = ((ActiveCell.Offset(0, -1) - ActiveCell.Offset(0, -2)) * 24)

ActiveCell.Offset(1, 0).Select

Loop

End Sub




Sub PayRate()

Range("H2").Select

Do Until ActiveCell.Offset(0, -6) = ""

Select Case ActiveCell.Offset(0, -4)

Case Is = "A1"
ActiveCell = ActiveCell.Offset(0, -1) * 55
Case Is = "A2"
ActiveCell = ActiveCell.Offset(0, -1) * 50
Case Is = "B1"
ActiveCell = ActiveCell.Offset(0, -1) * 45
Case Is = "B2"
ActiveCell = ActiveCell.Offset(0, -1) * 40
Case Is = "B3"
ActiveCell = ActiveCell.Offset(0, -1) * 35
Case Is = "C1"
ActiveCell = ActiveCell.Offset(0, -1) * 30
Case Is = "C2"
ActiveCell = ActiveCell.Offset(0, -1) * 25
Case Else
ActiveCell = "Error"

End Select

ActiveCell.Offset(1, 0).Select

Loop

End Sub

Enjoy your day
Marius Barnard
Excel Trainer


 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Sorting List Subtotals

If you find that you would prefer to show the items in a subtotalled list in a different order, eg ascending rather than descending, you can sort your list. To sort a subtotalled list, hide the detail rows and then sort the subtotal rows. When you sort a subtotalled list, the hidden detail rows are automatically moved with the subtotal rows.
IMPORTANT: If you do not hide the details rows before sorting a subtotalled list, your subtotals will be removed and all of the rows in your list will be reordered.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.11 secs.