Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdown toolbar with IF statements - Excel VBA

Status
Not open for further replies.

kalalala

Programmer
Sep 21, 2005
3
GB
The following code does the following:

Users selects/opens a file-> data from the selected file gets copied to the data in the source worksheet/file


Sub test()
Dim file_open As Variant
Dim WB As Workbook
file_open = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
Set WB = Workbooks.Open(Filename:=file_open)


With ThisWorkbook.Worksheets("Review Schedule & Metrics")
' read data from the source workbook
.Range("A10").Formula = WB.Worksheets("PM").Range("A10").Formula
End With


WB.Close False ' close the source workbook without saving any changes
Set WB = Nothing ' free memory
Application.ScreenUpdating = True ' turn on the screen updating
End Sub



Propsed:

1. Add a dropdown toolbar box where users can select an item (total of 6 items)
2. Each item in the list refers to a different set of data (i.e different range)
3. Depending on what item is selected, the code should go to the specified range for that item and copy over the data (as what is happening at the moment anyway)

For example:

If user selects item 1, this will copy over range A10 - A20.

If user selects item 2, this will copy over range A99 - A49..

etc


I am not sure of how i will be using the IF statements and making references to items in the drop down toolbar button?

Many thanks in advance
 


Hi,

Code:
Select Case iItem
  Case 1
    Set rng = Range("A10:A20")
  Case 2
    Set rng = Range("A49:A99")
End Select
WB.Worksheets("PM").Range("A10").Copy rng


Skip,

[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top