Remove not required sheets

I

ilyaskazi

Following are the sheet names containing in workbook:
Sheet1, Temp1, Test1, Check1, Sheet2, Test2, Work2, Pend2


Here if removed digits from sheet names, then:
Sheet1 matches Sheet2
Test1 matches Test2

And non matching names are:
Temp1, Check1, Work2, Pend2

So, what i actually need is to delete these all non matching sheet
through vba

+-------------------------------------------------------------------
|Filename: RmvSheets.zip
|Download: http://www.excelforum.com/attachment.php?postid=3670
+-------------------------------------------------------------------
 
S

STEVE BELL

This is crude code (untested). But the idea is to check each worksheet
against all the other sheets.
If no match is found than delete the worksheet.

Dim ws as Worksheet, wsn as String, wsi as Integer, i as integer, x as
integer

For each ws in Activeworkbook.Worksheets
x = 0
wsn = Left(ws.name,len(ws.name)-1)
wsi = ws.Index
for i = 1 to Activeworkbook.Worksheets.Count
if i <> wsi then
If Left(Sheets(i).name,len(Sheets(i).name)-1) = wsn
x = 1
end if
next

If x = 0 then
ws.delete
end if
Next
 
I

ilyaskazi

Excellent!!!

I hv checked and working perfect as per my requirement.
thankyou steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top