Advertisement
veronikaaa86

10. Steps

Sep 20th, 2022
1,747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub Steps()
  2.     Dim goal, i, allSteps As Integer
  3.     goal = 10000
  4.     i = 1
  5.    
  6.     Dim commandInput As String
  7.     commandInput = Range("A" & i)
  8.    
  9.     Do While commandInput <> "Going home"
  10.         Dim currentSteps As Integer
  11.         currentSteps = Range("A" & i)
  12.    
  13.         allSteps = allSteps + currentSteps
  14.        
  15.         i = i + 1
  16.        
  17.         If allSteps >= goal Then
  18.             Exit Do
  19.         End If
  20.        
  21.         commandInput = Range("A" & i)
  22.     Loop
  23.    
  24.     If commandInput = "Going home" Then
  25.         allSteps = allSteps + Range("A" & i + 1)
  26.     End If
  27.    
  28.     If allSteps >= goal Then
  29.         Debug.Print "Goal reached! Good job!"
  30.     Else
  31.         Debug.Print goal - allSteps & " more steps to reach goal."
  32.     End If
  33. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement