Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

vba code has bugs and errors. pleae leave comments withhow it was fixed and a co

ID: 3852298 • Letter: V

Question

vba code has bugs and errors. pleae leave comments withhow it was fixed and a copyable code

Sub TotalSales1()
    Dim lastDate As Date, total As Currency, i As Long, ws As Worksheet
  
    MsgBox "You'll now be asked for a date. Then the total of all " & _
        " sales up to that date will be totaled.", vbInformation, "Purpose"
    lastDate = InputBox("Enter the last date for the total.", "Last date")
    total = 0
    For Each ws In ActiveWorkbook
        With Worksheets("ws").Range("A3")
            Do Until .Offset(i, 0) = ""
                If .Offset(i, 0) <= lastDate Then total = total + .Offset(i, 2)
            Loop
        End With
    Next
    MsgBox "The total of all sales through " & Format(lastDate, "1/1/99") & " is " & _
        Format(total, "$#,##0"), vbInformation, "Sales Total"
End Sub

Explanation / Answer

i have fixed the bugs in your code ,please check modified code below

Sub TotalSales1()

Dim lastDate As Date, total As Currency, i As Long, ws As Worksheet

MsgBox "You'll now be asked for a date. Then the total of all " & _

" sales up to that date will be totaled.", vbInformation, "Purpose"

lastDate = InputBox("Enter the last date for the total.", "Last date")

total = 0

For Each ws In ActiveWorkbook.Worksheets

i = 0

With ws.Range("A3")

Do Until .Offset(i, 0) = ""

If .Offset(i, 0)
i = i + 1

Loop

End With

Next ws

MsgBox "The total of all sales through " & Format(lastDate, "d/m/yy") & " is " & _

Format(total, "$#,##0"), vbInformation, "Sales Total"

End sub