• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Application questions

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
 
Hi Brian ,

When you refer to anything on Chandoo's site , if possible please post a link to the relevant page / download.

It is possible that there may be additional explanations available at the link which members can go through before responding.

It is also possible that by making use of a downloadable workbook , members can run the code and see how it works.

As it stands , the variable storeNum appears to be an unnecessary variable , since no use is being made of it.

I am not able to understand your second question ; the InputBox statement is required to get user input as far as each store's sales are concerned. If this statement is not used , then how would this data be obtained ?

Narayan
 
Back
Top