|
-
Jan 17th, 2003, 07:21 AM
#1
Thread Starter
Lively Member
Printing Excel Spreadsheet
I'm attempting to print one or two sheets on an Excel Spreadsheet. I have a "Type Mismatch" when the line
"If Range("C9:J37") <> " " Then" is read. What I'm attempting
to query is "If the second sheet contains values in the range C9:J37 then, so that the sheet may be printed if there is values.
Would someone out there supply me with the correct string?
<vbcode>
'Select Sheet 2 for viewing.
Sheets("SheetTwo").Select
'If Sheet 2 contains inputed values.
If Range("C9:J37") <> " " Then
'Print Workbook.
ActiveWorkbook.PrintOut Copies:=1, Collate:=True
Else
Sheets("SheetOne").Select
'Print Selected Sheet [SheetOne].
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If
<vbcode>
-
Jan 17th, 2003, 11:18 AM
#2
Addicted Member
hi rba !
the reason why you get this error is, a range object with multipe cells have multiple values. So you can't write '<> ""'
You should loop through the range to find values (see example below. pls note this one is not tested
VB Code:
'Select Sheet 2 for viewing.
'? do you want do see this sheet if not use a reference
'like
set shtSheetTwo = aktiveworkbook.worksheets("SheetTwo")
'Sheets("SheetTwo").Select
'use a reference
'like
set rngSheetTwo = aktiveworkbook.worksheets("SheetTwo").Range("C9:J37")
'set a flag if we find values
bFindValues = false
'loop through the range
for each rngDummy in rngSheetTwo
'now look if we find values
if trim(rngDummy.value) <> vbnullstring then
'catched one so set flag to true and exit loop
bfindvalues = true
exit for
end if
next rngDummy
'If Sheet 2 contains inputed values. (flag = true)
If bFindValues Then
'Print Workbook.
ActiveWorkbook.PrintOut Copies:=1, Collate:=True
Else
Sheets("SheetOne").Select
'Print Selected Sheet [SheetOne].
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
End If
hope this helps
TheOnly
-
Jan 17th, 2003, 03:04 PM
#3
Thread Starter
Lively Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|