Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copying sheets from ListBox of names to a new worksheet

I want to copy worksheets from one workbook to another using a listbox
populated by worksheet names. How do I get the names from the listbox
into a statment to do the copying?
Help!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Copying sheets from ListBox of names to a new worksheet

I created a userform with a listbox and two commandbuttons:

Option Explicit
Public WhichWkbk As Workbook
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()
Dim mySheetNames() As String
Dim iCtr As Long
Dim jCtr As Long

With Me.ListBox1
ReDim mySheetNames(1 To .ListCount)

For iCtr = 1 To .ListCount
If .Selected(iCtr - 1) Then
jCtr = jCtr + 1
mySheetNames(jCtr) = .List(iCtr - 1)
End If
Next iCtr
End With

If jCtr = 0 Then
MsgBox "nothing selected!"
Else
ReDim Preserve mySheetNames(1 To jCtr)
WhichWkbk.Sheets(mySheetNames).Copy _
befo=Workbooks("book3.xls").Worksheets(1)
WhichWkbk.Activate
End If

Unload Me

End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long

Set WhichWkbk = ActiveWorkbook

Me.ListBox1.MultiSelect = fmMultiSelectMulti

For iCtr = 1 To WhichWkbk.Sheets.Count
With Sheets(iCtr)
If .Visible = xlSheetVisible Then
Me.ListBox1.AddItem .Name
End If
End With
Next iCtr
End Sub


BlackSox wrote:

I want to copy worksheets from one workbook to another using a listbox
populated by worksheet names. How do I get the names from the listbox
into a statment to do the copying?
Help!


--

Dave Peterson
Reply
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
real bug - defined names & copying worksheet DonJ_Austin Excel Discussion (Misc queries) 0 January 25th 10 12:04 AM
COPYING FORMULA CONTAINING NAMES/RELATIVE RANGE NAMES Bricol Excel Discussion (Misc queries) 0 July 8th 08 03:54 PM
Copying rows from 2 sheets to a new worksheet based on date criter Phill_Morgan Excel Discussion (Misc queries) 9 August 29th 07 08:03 AM
Copying and using formulas including worksheet names Isissoft Excel Discussion (Misc queries) 3 May 5th 07 10:12 PM


All times are GMT +1. The time now is 03:45 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"