Compare items from Listbox to open workbook name

weakvba

New Member
Joined
Aug 6, 2011
Messages
5
Hi

i want to compare items in listbox to list of open workbooks, where the name matches i want to copy that sheet into a new sheet. problem here is the list of open workbooks have same named sheet so when i run the macro it copies sheet(for example accounts) from all the open booksbooks..Problem i am facing is if there is only one workbook containing sheet called accounts it works fine but if there are more then one workbooks open with a sheet called Accounts , it will paste all those sheets . can anyone help please as in how can i overcome this problem of selecting items from list box and when that name matches open workbooks ,sheet from only that workbook is copied

my code is

Sub Clic()
'Function Initialize()
Dim shtToCopy As Worksheet
Dim wkbDest As Workbook
Set wkbDest = Workbooks("working test")
Dim wb As Workbook
For Each wb In Workbooks




On Error Resume Next 'Will continue if an error results

'***********************
If Workbooks(ListBox1.Value).Select = wb.Name Then
wb.Activate
Set shtToCopy = wb.Sheets("Accounts")

shtToCopy.Copy wkbDest.Sheets(3)
'Delete.Sheet (3)
End If
Next wb
end sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,214,592
Messages
6,120,433
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top