Results 1 to 3 of 3

Thread: Printing Excel Spreadsheet

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    87

    Exclamation 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>

  2. #2
    Addicted Member
    Join Date
    Oct 2000
    Location
    Vienna/Austria
    Posts
    132
    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:
    1. 'Select Sheet 2 for viewing.
    2. '? do you want do see this sheet if not use a reference
    3. 'like
    4. set shtSheetTwo = aktiveworkbook.worksheets("SheetTwo")
    5. 'Sheets("SheetTwo").Select
    6.  
    7.  
    8. 'use a reference
    9. 'like
    10. set rngSheetTwo = aktiveworkbook.worksheets("SheetTwo").Range("C9:J37")
    11.  
    12. 'set a flag if we find values
    13. bFindValues = false
    14.  
    15. 'loop through the range
    16. for each rngDummy in rngSheetTwo
    17.     'now look if we find values
    18.     if trim(rngDummy.value) <> vbnullstring then
    19.            'catched one so set flag to true and exit loop
    20.            bfindvalues = true
    21.            exit for
    22.     end if
    23. next rngDummy
    24.  
    25. 'If Sheet 2 contains inputed values. (flag = true)
    26. If bFindValues Then
    27. 'Print Workbook.
    28. ActiveWorkbook.PrintOut Copies:=1, Collate:=True
    29. Else
    30. Sheets("SheetOne").Select
    31. 'Print Selected Sheet [SheetOne].
    32. ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
    33. End If

    hope this helps

    TheOnly

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2002
    Posts
    87
    Thanks, the only!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width