Avatar of brothertruffle880
brothertruffle880
Flag for United States of America asked on

Excel 2010 VBA - Setting variables and constants.

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
Else
CommissionAmt = TotalSales * bronze
End If
Cells(Count, 7).Value = CommissionAmt
Next Count
End Sub
Microsoft Excel

Avatar of undefined
Last Comment
Martin Liss

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Martin Liss

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Norie

To declare as a constant.

Const silver = 0.04

Open in new window

Martin Liss

Glad I was able to help.

Marty - MVP 2009 to 2012
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck