Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Array To View Specific Sheet(s)

Using a macro I need to view specific worksheets if they have content. I
will always want my "Invoice" sheet and if on the Invoice sheet, cell B12 has
a value I want to view the Invoice and Labour sheet. If cell B13 has a value
I also want to view the Materials sheet.

My macro, shown below, halts at the line "Sheets(Array(prtWhat)).Select".

How can I dynamically build the proper statement...
"Sheets(Array("Invoice", "Labour", "Materials")).Select"

Please help.

Sub ViewTest()

prtWhat = "Invoice"
Labour = ", Labour"
Materials = ", Materials"
If Range("B12").Value < "" Then
prtWhat = prtWhat & Labour
Else
prtWhat = prtWhat
End If
If Range("B13").Value < "" Then
prtWhat = prtWhat & Materials
Else
prtWhat = prtWhat
End If

MsgBox (prtWhat)

Sheets(Array(prtWhat)).Select
Sheets("Invoice").Activate
ActiveWindow.SelectedSheets.PrintPreview
Sheets("Invoice").Select
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Array To View Specific Sheet(s)

Don't use the Array function, rather, use the Split function... its first
argument is a String which you can build dynamically. For example...

Dim SheetStr As String
...........
...........
SheetStr = "Invoice"
With Sheets(SheetStr)
If .Range("B12").Value < "" Then SheetStr = SheetStr & ",Labour"
If .Range("B13").Value < "" Then SheetStr = SheetStr & ",Materials"
End With
Sheets(Split(SheetStr, ",")).Select

Note the comma in front of the additional sheet names that are being
concatenated... that is the delimiter that is used in the Split function
call (don't add any spaces around those comma or else the spaces will end up
in the sheet names).

--
Rick (MVP - Excel)



"GEdwards" wrote in message
...
Using a macro I need to view specific worksheets if they have content. I
will always want my "Invoice" sheet and if on the Invoice sheet, cell B12
has
a value I want to view the Invoice and Labour sheet. If cell B13 has a
value
I also want to view the Materials sheet.

My macro, shown below, halts at the line "Sheets(Array(prtWhat)).Select".

How can I dynamically build the proper statement...
"Sheets(Array("Invoice", "Labour", "Materials")).Select"

Please help.

Sub ViewTest()

prtWhat = "Invoice"
Labour = ", Labour"
Materials = ", Materials"
If Range("B12").Value < "" Then
prtWhat = prtWhat & Labour
Else
prtWhat = prtWhat
End If
If Range("B13").Value < "" Then
prtWhat = prtWhat & Materials
Else
prtWhat = prtWhat
End If

MsgBox (prtWhat)

Sheets(Array(prtWhat)).Select
Sheets("Invoice").Activate
ActiveWindow.SelectedSheets.PrintPreview
Sheets("Invoice").Select
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Array To View Specific Sheet(s)

Try the below....It is always better to mention the sheet name while
referring to the range. Instead of Range("B12") mention as
Sheets("Sheetname").Range("B12")


Sub ViewTest()
Dim strSheets As String

strSheets = "Invoice"
If Range("B12") < "" Then strSheets = strSheets & ",Labour"
If Range("B13") < "" Then strSheets = strSheets & ",Materials"

Sheets(Split(strSheets, ",")).Select
Sheets("Invoice").Activate
ActiveWindow.SelectedSheets.PrintPreview
End Sub




--
Jacob


"GEdwards" wrote:

Using a macro I need to view specific worksheets if they have content. I
will always want my "Invoice" sheet and if on the Invoice sheet, cell B12 has
a value I want to view the Invoice and Labour sheet. If cell B13 has a value
I also want to view the Materials sheet.

My macro, shown below, halts at the line "Sheets(Array(prtWhat)).Select".

How can I dynamically build the proper statement...
"Sheets(Array("Invoice", "Labour", "Materials")).Select"

Please help.

Sub ViewTest()

prtWhat = "Invoice"
Labour = ", Labour"
Materials = ", Materials"
If Range("B12").Value < "" Then
prtWhat = prtWhat & Labour
Else
prtWhat = prtWhat
End If
If Range("B13").Value < "" Then
prtWhat = prtWhat & Materials
Else
prtWhat = prtWhat
End If

MsgBox (prtWhat)

Sheets(Array(prtWhat)).Select
Sheets("Invoice").Activate
ActiveWindow.SelectedSheets.PrintPreview
Sheets("Invoice").Select
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find specific value in array of array formula DzednConfsd Excel Worksheet Functions 2 January 13th 09 06:19 AM
view different parts of sheet - split view mami Excel Discussion (Misc queries) 2 November 10th 08 01:04 PM
custom view to display specific toolbars pwrichcreek Excel Programming 6 December 13th 07 10:50 PM
View Custom View with Sheet Protection John H[_2_] New Users to Excel 1 February 16th 07 05:54 PM
specific user view G Excel Discussion (Misc queries) 0 January 24th 06 11:33 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"