LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Copying Named Ranges based on ListBox Results

Hello everyone,
All of you have been wonderful in my search for VBA understanding. This is
the first time I have a question for you.

I have 5 separate worksheets that contain various regions of data.
Eventually they will exceed Excel's row limit if they are combined, which is
why they are separated to begin with. Each worksheet has the same columns,
but the data is specific to that region. I have also created dynamic named
ranges for each worksheet, since their size will increase every month. Using
a userform, I need to be able choose one or more regions from a list of
regions (which corresponds to the sheet names and the named ranges), then
copy and paste the data from each chosen worksheet into the €śMaster€ť
worksheet. Since the column headings are all the same, the €śMaster€ť
worksheet already has them listed.

For example, I need the userform to allow me to choose Northeast, Midwest,
and Southeast from the list below. When I click a button, the data in
Northeast (by named range?) would be pasted into the €śMaster€ť worksheet,
starting in the second row. Then the data in Midwest would be pasted below
the Northeast data, and then the data in Southeast would be pasted below the
Midwest data.

<Regions
Northeast
Southeast
Midwest
Southwest
West

Below is the coding I have so far. The forms name is Change_Region, and
the regions are listed in a named range called Regions. Any help you can
provide would be very much appreciated. Thank you.

--------------------------------------------------
Private Sub CommandButton2_Click()

Dim res As Variant
Dim Last As Integer

For i = 0 To Change_Region.ListBox1.ListCount - 1
If Change_Region.ListBox1.Selected(i) Then
res = Application.VLookup(Change_Region.ListBox1.Text = i,
Worksheets("LISTS").Range("Regions"), 1, False)
If Not IsError(res) Then
Last = Columns("A:A").Find(What:="", LookAt:=xlWhole).Row
Change_Region.Hide
Application.ScreenUpdating = False
Worksheets(res).Select
Worksheets(res).Range(i).Copy Worksheets("Master").Range(Last +
1, 1)
Else
Change_Region.Hide
MsgBox "Match not made. Please try again."
Change_Region.Show
End If
Else
Change_Region.ListBox1.Clear
MsgBox "Please choose a region or click Cancel."
End If
Next i

End Sub
--------------------------------------------------
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying Named Ranges in Chart Series Revolvr Charts and Charting in Excel 1 March 18th 10 12:21 PM
Copying Worksheets which contain Named Ranges Terry Bennett Excel Worksheet Functions 0 June 25th 09 05:04 PM
Copying Named Ranges Tom Perlman Excel Discussion (Misc queries) 4 December 14th 06 07:34 PM
union of named ranges based only on the names of those ranges sloth Excel Programming 3 October 2nd 06 03:18 AM
Copying named ranges from one sheet to another Mark Stephens Excel Programming 3 August 4th 05 02:54 PM


All times are GMT +1. The time now is 03:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"