By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,587 Members | 1,079 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,587 IT Pros & Developers. It's quick & easy.

Selecting Sheets (Excel)

P: 18
I need to select a group of sheets, where the inclusion of each sheet in the workbook is based on a value in each sheet. (For example, select all sheets which have a 1 in cell A1.)

How can I do this in VisualBasic?

Bertie
Apr 19 '07 #1
Share this Question
Share on Google+
2 Replies


SammyB
Expert 100+
P: 807
I need to select a group of sheets, where the inclusion of each sheet in the workbook is based on a value in each sheet. (For example, select all sheets which have a 1 in cell A1.)

How can I do this in VisualBasic?

Bertie
Expand|Select|Wrap|Line Numbers
  1. Sub SelectOne()
  2.     Dim s() As String
  3.     Dim ws As Worksheet
  4.     Dim i As Integer
  5.     i = 0
  6.     For Each ws In Worksheets
  7.         If ws.Cells(1, 1).Value = 1 Then
  8.             ReDim Preserve s(i)
  9.             s(i) = ws.Name
  10.             i = i + 1
  11.         End If
  12.     Next ws
  13.     Worksheets(s).Select
  14. End Sub
HTH --Sam
Apr 19 '07 #2

P: 18
Expand|Select|Wrap|Line Numbers
  1. Sub SelectOne()
  2.     Dim s() As String
  3.     Dim ws As Worksheet
  4.     Dim i As Integer
  5.     i = 0
  6.     For Each ws In Worksheets
  7.         If ws.Cells(1, 1).Value = 1 Then
  8.             ReDim Preserve s(i)
  9.             s(i) = ws.Name
  10.             i = i + 1
  11.         End If
  12.     Next ws
  13.     Worksheets(s).Select
  14. End Sub
HTH --Sam
Thanks a lot! Problem solved!

Regards, B
Apr 20 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.