ShogunPatch
Board Regular
- Joined
- May 8, 2009
- Messages
- 52
I have a workbook comprising two worksheets, "Form" and "Lists".
Many of the columns in "Forms" are restricted by validation lists defined in "Lists", e.g. one column is for currency and users select available currencies from a drop down box, available options for which are defined in a range called "CurrencyDetails" in "Lists" (which is protected). The particular range is currently quite small, as I only have a short list of currencies setup for now but is spread across two columns: one for the full currency name and one for a code (e.g. 'US Dollar' and 'USD')
Essentially, I want to create a command button which will open a form where users can create new currencies to add to the list.
Using my existing, basic knowledge of Excel, cobbling together code from recorded macros and with the added help of existing posts on forums such as this and an extremely helpful YouTube video I have so far managed to:
Of course because the range is increased by one row everytime a currency is added it column/row coordinates are never up to date.
I hope the above is clear; I'm sure this is very basic programming but would appreciate any help with this last bit of this macro.
Cheers.
Patch
Execution code for the "OK" button on my form attached below.
Many of the columns in "Forms" are restricted by validation lists defined in "Lists", e.g. one column is for currency and users select available currencies from a drop down box, available options for which are defined in a range called "CurrencyDetails" in "Lists" (which is protected). The particular range is currently quite small, as I only have a short list of currencies setup for now but is spread across two columns: one for the full currency name and one for a code (e.g. 'US Dollar' and 'USD')
Essentially, I want to create a command button which will open a form where users can create new currencies to add to the list.
Using my existing, basic knowledge of Excel, cobbling together code from recorded macros and with the added help of existing posts on forums such as this and an extremely helpful YouTube video I have so far managed to:
- Create the required "Create New Currency" button and get that button to:
- Open and unlock the "Lists" sheet
- Select the correct range by name "CurrencyDetails"
- Add one row to it
- Open a "NewCurrencyDetails" form
- Design the "NewCurrencyDetails"; the form requires two inputs (currency name & currency code) and also has "OK" and "Cancel" buttons
- Get the "Cancel" button to work and the "OK" button to start adding the details to the relevant named list, i.e. specifically to:
- Input the values from the form into the correct two cells (the two newly created cells at the bottom of the named range)
Of course because the range is increased by one row everytime a currency is added it column/row coordinates are never up to date.
I hope the above is clear; I'm sure this is very basic programming but would appreciate any help with this last bit of this macro.
Cheers.
Patch
Execution code for the "OK" button on my form attached below.
Code:
Private Sub CmdAddCurrency_Click()
Range("CurrencyNameInsertionPoint") = Me.TxtCurrencyName
Range("CurrencyCodeInsertionPoint") = Me.TxtCurrencyCode
Me.Hide
Application.Goto Reference:="CurrencyDetails"
ActiveWorkbook.Worksheets("Lists").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Lists").Sort.SortFields.Add Key:=Range("G8:G14"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Lists").Sort
.SetRange Range("G8:H14")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub