helraizer Posted March 20, 2008 Share Posted March 20, 2008 Hi folks, I am making a spreadsheet for a foreign exchange bureau, on the loading of the page it asks the operator to add the day's exchange rates. I have the following code in Excel VBA Private Sub Worksheet_Open() Worksheets("Rates").Activate 'GBP to Euro Dim varInput As String varInput = InputBox("Please enter today's rates from GBP to EUR", "Exchange Rates", "e.g. 0.765") Range("C11").Select If(varInput = "") Then Selection.Value = Range("C11").Value Elseif(varInput = "e.g. 0.765") Then MsgBox "Please enter a proper value.", vbOkOnly, "System Message" Else Selection.Value = varInput 'GBP to American Dollars Dim varInput As String varInputa = InputBox("Please enter today's rates from GBP to USD", "Exchange Rates", "e.g. 0.765") Range("C12").Select If(varInputa = "") Then Selection.Value = Range("C12").Value Elseif(varInputa = "e.g. 0.765") Then MsgBox "Please enter a proper value.", vbOkOnly, "System Message" Else Selection.Value = varInputa 'GBP to Japanese Yen Dim varInputb As String varInputb = InputBox("Please enter today's rates from GBP to YEN", "Exchange Rates", "e.g. 0.765") Range("C13").Select If(varInputb = "") Then Selection.Value = Range("C13").Value Elseif(varInputb = "e.g. 0.765") Then MsgBox "Please enter a proper value.", vbOkOnly, "System Message" Else Selection.Value = varInputb 'GBP to Canadian Dollars Dim varInputc As String varInputc = InputBox("Please enter today's rates from GBP to CAD", "Exchange Rates", "e.g. 0.765") Range("C14").Select If(varInputc = "") Then Selection.Value = Range("C14").Value Elseif(varInputc = "e.g. 0.765") Then MsgBox "Please enter a proper value.", vbOkOnly, "System Message" Else Selection.Value = varInputc 'GBP to Australian Dollars Dim varInputd As String varInputd = InputBox("Please enter today's rates from GBP to AUD", "Exchange Rates", "e.g. 0.765") Range("C15").Select If(varInputd = "") Then Selection.Value = Range("C15").Value Elseif(varInputd = "e.g. 0.765") Then MsgBox "Please enter a proper value.", vbOkOnly, "System Message" Else Selection.Value = varInputd End Sub That works perfectly, but at the moment if the value is the default value of the InputBox ("e.g. 0.765") it just throws up the error message and then moves on to the next part. How would I make it so that, without having to repeat the first bit of code (inputbox code) each time, if the elseif statement is executed it gives the error message (msgbox) and then prompts them again to enter a value for the same rate? Hope that makes sense, Sam Quote Link to comment https://forums.phpfreaks.com/topic/97121-excel-vba-help-needed/ Share on other sites More sharing options...
keeB Posted March 29, 2008 Share Posted March 29, 2008 While loop? Quote Link to comment https://forums.phpfreaks.com/topic/97121-excel-vba-help-needed/#findComment-504058 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.