Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

writing VBA code for an excel sheet, i keep getting run time error 1004 application or object defined error. my code reads as follows.

writing VBA code for an excel sheet, i keep getting run time error 1004 application or object defined error.

my code reads as follows.

Option Explicit

Sub tours()

'Define Input variables

Dim p As Integer

Dim h As Integer

Dim sbp As Integer

Dim lbp As Integer

Dim ehp As Double

p = Worksheets("sheet1").Range("d6").Value

h = Worksheets("sheet1").Range("d8").Value

sbp = Worksheets("sheet1").Range("e30").Value

lbp = Worksheets("sheet1").Range("e31").Value

ehp = Worksheets("sheet1").Range("e33").Value

' [There should be five total input variables.]

'Define Output variables

Dim NSB As Integer

Dim NLB As Integer

Dim SE As Currency

Dim LE As Currency

Dim SEHC As Currency

Dim LEHC As Currency

Dim TSBP As Currency

Dim TLBP As Currency

Dim ECH As Integer

Dim tp As Currency

'Check to see if over 5 hours long

If h > 5 Then ECH = (h - 5)

If h < 5 Then ECH = 0

'Find correct number of each bus

If p > 90 Then NSB = 0 And NLB = 2

If p > 70 Then NSB = 1 And NLB = 1

If p > 55 Then NSB = 2 And NLB = 0

If p > 35 Then NSB = 0 And NLB = 1

If p < 35 Then NSB = 1 And NLB = 0

'Find extension price for buses

SE = NSB * sbp

LE = NLB * lbp

' [Now that you know the number of buses, you can figure out the extended prices.]

' [This is simply the number of buses times the appropriate base rate.]

'Calculate extra hourly charge, if any

If ECH > 0 Then SEHC = SE * ehp * ECH And LEHC = LE * ehp * ECH

If ECH >= 5 Then SEHC = (4 * ehp * SE) And LEHC = (4 * ehp * LE)

' [Here you can do some checks to see how many "extra" hours need to be charged.]

' [Remember that the number of extra hours that are charged for is capped at 4.]

'Add up the totals

TSBP = SE + SEHC

TLBP = LE + LEHC

tp = TSBP + TLBP

' [Now you just add up the various charges for the total bus prices, which also combine into the total.]

'Outputs

Worksheets("sheet1").Range("d12").Value = ECH

Worksheets("sheet1").Range("c16").Value = NSB

Worksheets("sheet1").Range("c18").Value = SE

Worksheets("sheet1").Range("e16").Value = NLB

Worksheets("sheet1").Range("e18").Value = LE

Worksheets("sheet1").Range("c20").Value = SEHC

Worksheets("sheet1").Range("e20").Value = LEHC

Worksheets("sheet1").Range("c22").Value = TSBP

Worksheets("sheet1").Range("e22").Value = TLBP

Worksheets("sheet1").Range("d24").Value = tp

' [Now spit out all 10 of the output variables to their appropriate places on the spreadsheet.]

End Sub

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question