Hi everyone,
I am learning macros through Chandoo's 5-part series. In his part-2 series (http://chandoo.org/wp/2011/08/30/variables-conditions-loops-in-vba/), in the example provided, I tried to make some changes and learn.
1. When it ask for input for the "Sales for the Stoe", it accepts any thing even a string.
2. Tried to modify the code to accept only numbers.
-------------------------------------------------------------------------
-------------------------------------------------------------------------
3. It works ok and moves to next field if I input any 'Text' but I want the task to repeat until it accepts the number for that pertcular store. How I can I do that.
Thanks in advance..
Here is the original file...
http://img.chandoo.org/vba/crash-course/variables-conditions-and-loops.xls
I am learning macros through Chandoo's 5-part series. In his part-2 series (http://chandoo.org/wp/2011/08/30/variables-conditions-loops-in-vba/), in the example provided, I tried to make some changes and learn.
1. When it ask for input for the "Sales for the Stoe", it accepts any thing even a string.
2. Tried to modify the code to accept only numbers.
-------------------------------------------------------------------------
Code:
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 storeSales As Long
Dim storeNum As Integer
Dim reason As String
Dim store As Range
storeNum = 1
For Each store In Range("C7:C30")
store.Value = InputBox("Sales for Store " & storeNum)
If Not IsNumeric(store.Value) Then
MsgBox "Only numbers are allowed!"
store.Value = vbNullString
End If
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
3. It works ok and moves to next field if I input any 'Text' but I want the task to repeat until it accepts the number for that pertcular store. How I can I do that.
Thanks in advance..
Here is the original file...
http://img.chandoo.org/vba/crash-course/variables-conditions-and-loops.xls
Last edited by a moderator: