ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy multiple sheets using a list box (https://www.excelbanter.com/excel-programming/363165-copy-multiple-sheets-using-list-box.html)

kev_06[_3_]

Copy multiple sheets using a list box
 

I'm trying to copy multiple sheets from one workbook to a new workbook.
The problem is that I'm trying to copy sheets one at a time using a
loop. The list box changes when the user enters different sheet names
into the list box. So far I have tried:

intcopy = 0

For intcopy = 0 To listbox1.Index
Sheets(Array(listbox1.List(intcopy))).Copy
intcopy = intcopy + 1
Next

With this code I get a 'Subscript of of range' error. I'd like the
selected sheets be put into one new workbook. Any suggestions?


--
kev_06
------------------------------------------------------------------------
kev_06's Profile: http://www.excelforum.com/member.php...o&userid=35046
View this thread: http://www.excelforum.com/showthread...hreadid=548008


Chip Pearson

Copy multiple sheets using a list box
 
Try

Dim Ndx As Long
With Me.ListBox1
For Ndx = 0 To .ListCount - 1
If .Selected(Ndx) = True Then
Worksheets(.List(Ndx)).Copy
after:=Worksheets(Worksheets.Count)
End If
Next Ndx
End With



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"kev_06"
wrote in message
...

I'm trying to copy multiple sheets from one workbook to a new
workbook.
The problem is that I'm trying to copy sheets one at a time
using a
loop. The list box changes when the user enters different sheet
names
into the list box. So far I have tried:

intcopy = 0

For intcopy = 0 To listbox1.Index
Sheets(Array(listbox1.List(intcopy))).Copy
intcopy = intcopy + 1
Next

With this code I get a 'Subscript of of range' error. I'd like
the
selected sheets be put into one new workbook. Any suggestions?


--
kev_06
------------------------------------------------------------------------
kev_06's Profile:
http://www.excelforum.com/member.php...o&userid=35046
View this thread:
http://www.excelforum.com/showthread...hreadid=548008





All times are GMT +1. The time now is 12:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com