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 Workbook_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
-
-
End If
-
-
'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
-
End If
-
-
'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
-
End If
-
-
'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
-
End If
-
-
'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 If
-
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
1 1217
Here is one way...
Private Sub Workbook_Open()
Dim varInput As String
Dim varInputa As String
Dim varInputb As String
Dim strDefault As String
Worksheets("Rates").Activate
'GBP to Euro
strDefault = "Please enter today's rates from GBP to EUR"
StartOver:
varInput = InputBox(strDefault, "Exchange Rates", "e.g. 0.765")
If (varInput = "") Then
Exit Sub ' user cancelled
ElseIf Val(varInput) = 0 Then
strDefault = "Please Try Again - Enter Today's GBP/EUR Rate "
GoTo StartOver
Else
Range("C11").Value = varInput
End If
Sign in to post your reply or Sign up for a free account.
Similar topics
by: ian castleden |
last post by:
From time to time I see requests for some sort of python MS Excel
interface/software.
I have written just such software 100% python (works with Jython too! at
least it did a year ago).
It was...
|
by: Prakash |
last post by:
Hi,
We face problems uploading excel (with macros) documents using HTML
File Upload.
The file contents are corrupted while viewing the same. However, we
are able to upload excel (w/o. macros)...
|
by: Matthew Wieder |
last post by:
I have the following requirements:
Build a stand-alone C# application that asks the user to click in a cell
in an Excel spreadsheet, and then displays the address of that cell in
the C#...
|
by: mattmerc |
last post by:
Hi all,
We have all seen lot of method for exporting datagrids to Excel. I have
a slightly different need. I think it should be easy to accomplish but
I am not sure how. I would like when a user...
|
by: John Machin |
last post by:
I am pleased to announce a new general release (0.5.2) of xlrd, a Python
package for extracting data from Microsoft Excel spreadsheets.
CHANGES:
* Book and sheet objects can now be pickled and...
|
by: rdemyan via AccessMonster.com |
last post by:
I want to make sure that I'm closing an opened spreadsheet correctly. I've
been having some locking up problems. The following code adds a dummy row to
the spreadsheet to ensure that that the data...
|
by: madeleine |
last post by:
I'm hoping the answer to this is that I'm just doing something silly,
but I'm really scratching my head over this one. I'm importing data
from multiple workbooks, each workbook has a sheet called...
|
by: dan_roman |
last post by:
Hi,
I developed a script with a nice interface in Tkinter that allows me to
edit some formulas and to generate an Excel worksheet with VBA macros
within it. The script runs perfectlly in Office...
|
by: TG |
last post by:
hi!
I am trying to create a sql server table from an excel sheet.
Here is the code I have:
'This procedure the xlsx file and dumps it to a table in SQL Server
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |