Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/97121-excel-vba-help-needed/
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.