Excel to Access Code Question

foxhound

Board Regular
Joined
Mar 21, 2003
Messages
182
Hello,

How would I accomplish the following? There are multiple sheets ranging from "Sheet1 (1)" to "Sheet1 (?)" that follow the pattern. I do not always know what the starting number or ending number will be. I want to select all the sheets where the first 6 characters of the sheet name is "Sheet1 (" and delete them.

Sheets(Array("Sheet1 (4)", "Sheet1 (5)","Sheet1 (6)")).delete
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
This goes slightly further and if the text 'Sheet1' is anywhere in the sheet name, it will delete it. If you'd like to still be specific and only test the first 6 characters, then you substitute a LEFT(objSheet.Name,6)

Code:
Public Sub ShowSheets()
Dim objSheet As Object   ' or you can use As Worksheet
Dim strTest As String

strTest = "Sheet1"

For Each objSheet In Sheets
  If InStr(objSheet.Name,strTest) > 0 Then
    ' Delete the Current Sheet Code
  End If
Next

End Sub

Did you, uh, goof and mean to post this in the Excel forum? Or is there more to this question that you forgot to post?

Mike
 
Upvote 0
Hi Mike,

Thanks for the quick reply. I will give it a shot. I am running this code in Access and I know that sometimes there are differences in how Access and Excel process code like "in string" versus "left". That is why I posted it here.

Thanks again :)
 
Upvote 0
Got it, my mistake then. I'm fairly certain there are numerous examples of how to run xls from Access using the search utility - but it's relatively easy to repost if you need it.

Mike
 
Upvote 0

Forum statistics

Threads
1,221,672
Messages
6,161,199
Members
451,688
Latest member
Gregs44132

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