brian sullivan
Member
Greetings Chandoo Community,
I'm reaching out to verify some usage questions I have with VBA macros. The macro example below is one provided on the Chandoo Website. However, I have some validation questions on the mechanical reasons behind the code. I feel my knowledge base is solid, but want to expand it to greater levels. (I have indicated letters throughout the code as reference points).
VBA QUESTIONS
A. StoreNum =1 - Is this code required because it directs the For Each Store (Code) with a starting point Store Number 1?
B. If you where going to remove the Inputbox from the code; is the appropriate adjustment store.value= if store.value <
C.
CHANDOO MACRO
Sub captureSales()
'when you run this macro, it will take the sales of all the 24 stores we own
'it will ask for a reason if the sales are too low or too high
Dim storeNum As Integer
Dim reason As String
Dim store As Range
Question A . storeNum = 1
For Each store In Range("C7:C30")
store.Value = Question B. InputBox("Sales for Store " & storeNum)
If store.Value < 500 Or store.Value > 5000 Then
reason = InputBox("Why are the sales deviated?", "Reason for Deviation", "Reason for Deviation")
store.Offset(, 1).Value = reason
End If
storeNum = storeNum + 1
Next store
End Sub
I'm reaching out to verify some usage questions I have with VBA macros. The macro example below is one provided on the Chandoo Website. However, I have some validation questions on the mechanical reasons behind the code. I feel my knowledge base is solid, but want to expand it to greater levels. (I have indicated letters throughout the code as reference points).
VBA QUESTIONS
A. StoreNum =1 - Is this code required because it directs the For Each Store (Code) with a starting point Store Number 1?
B. If you where going to remove the Inputbox from the code; is the appropriate adjustment store.value= if store.value <
C.
CHANDOO MACRO
Sub captureSales()
'when you run this macro, it will take the sales of all the 24 stores we own
'it will ask for a reason if the sales are too low or too high
Dim storeNum As Integer
Dim reason As String
Dim store As Range
Question A . storeNum = 1
For Each store In Range("C7:C30")
store.Value = Question B. InputBox("Sales for Store " & storeNum)
If store.Value < 500 Or store.Value > 5000 Then
reason = InputBox("Why are the sales deviated?", "Reason for Deviation", "Reason for Deviation")
store.Offset(, 1).Value = reason
End If
storeNum = storeNum + 1
Next store
End Sub