We help IT Professionals succeed at work.
Get Started

Excel 2010 VBA - Setting variables and constants.

Last Modified: 2012-07-09
I want to set a commission rate of 4% as a constant and when I run my procedure I get the error message  "Object required"  I have no idea what this means.

Dim silver As Double
Set silver = 0.04

Here is my procedure.  It's a simple "learning VBA" example:
(I'm calculating commissions for sales people)
Option Explicit
Dim TotalSales As Currency
Dim CommissionAmt As Currency
Dim Count As Integer

Public Sub Commission()
Dim gold As Double
Set gold = 0.04
Dim silver As Double
Set silver = 0.04
Dim bronze As Double
Set bronze = 0.02
For Count = 1 To 11
TotalSales = Cells(Count, 6).Value
If TotalSales > 10000 Then
CommissionAmt = TotalSales * gold
ElseIf TotalSales > 7000 Then
CommissionAmt = TotalSales * silver
CommissionAmt = TotalSales * bronze
End If
Cells(Count, 7).Value = CommissionAmt
Next Count
End Sub
Watch Question
Keep everyone healthy; Wear a mask - Social distance - Don't touch your face - Wash your hands for 20 seconds
Most Valuable Expert 2017
Distinguished Expert 2020
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE