ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Remove not required sheets (https://www.excelbanter.com/excel-programming/336382-remove-not-required-sheets.html)

ilyaskazi[_55_]

Remove not required sheets
 

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 a
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
+-------------------------------------------------------------------

--
ilyaskaz
-----------------------------------------------------------------------
ilyaskazi's Profile: http://www.excelforum.com/member.php...fo&userid=2396
View this thread: http://www.excelforum.com/showthread.php?threadid=39291


STEVE BELL

Remove not required sheets
 
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

--
steveB

Remove "AYN" from email to respond
"ilyaskazi" wrote
in message ...

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 a
Temp1, Check1, Work2, Pend2

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


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

--
ilyaskazi
------------------------------------------------------------------------
ilyaskazi's Profile:
http://www.excelforum.com/member.php...o&userid=23969
View this thread: http://www.excelforum.com/showthread...hreadid=392911




ilyaskazi[_58_]

Remove not required sheets
 

Excellent!!!

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

--
ilyaskaz
-----------------------------------------------------------------------
ilyaskazi's Profile: http://www.excelforum.com/member.php...fo&userid=2396
View this thread: http://www.excelforum.com/showthread.php?threadid=39291


STEVE BELL

Remove not required sheets
 
You are very welcome!

--
steveB

Remove "AYN" from email to respond
"ilyaskazi" wrote
in message ...

Excellent!!!

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


--
ilyaskazi
------------------------------------------------------------------------
ilyaskazi's Profile:
http://www.excelforum.com/member.php...o&userid=23969
View this thread: http://www.excelforum.com/showthread...hreadid=392911





All times are GMT +1. The time now is 10:27 AM.

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