View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Selecting multiple ranges

I've found that it's always a pain to get headers/footers correct. And
columnwidths and rowheights to do what I want.

One alternative is to copy the worksheet to a new workbook, change everything to
values, delete the columns, print the new worksheet and then close the new
workbook without saving.

If you think that's something you want to try:

Option Explicit
Sub testme()
Dim tempWks As Worksheet
Dim curWks As Worksheet
Dim rng As Range
Dim iCol As Long
Dim LastCol As Long

Set curWks = Worksheets("sheet1")
curWks.Select

Set rng = Nothing
On Error Resume Next
Set rng = Application.InputBox(Prompt:="Select a bunch of cells", Type:=8)
On Error GoTo 0

If rng Is Nothing Then
Exit Sub 'cancel
End If

With curWks
If rng.Parent.Name < .Name Then
MsgBox "Please select something on: " & .Name
Exit Sub
End If

Set rng = Intersect(.Rows(1), rng.EntireColumn).EntireColumn
.Copy 'to a new workbook
End With

Set tempWks = ActiveSheet
With tempWks
With .UsedRange
.Copy
.PasteSpecial Paste:=xlValues
End With
LastCol = .Cells.SpecialCells(xlCellTypeLastCell).Column
For iCol = LastCol To 1 Step -1
If Intersect(curWks.Columns(iCol), rng) Is Nothing Then
.Columns(iCol).Delete
End If
Next iCol

'save some trees
.PrintOut preview:=True

'uncomment when you're done testing
.Parent.Close savechanges:=False

End With
End Sub


wrote:

I am trying to allow users to print only selected columns from a
datasheet. So they select the columns they want to print and tey are
pasted to a hidden worksheet contiguously and printed. I am using:
cntA = Selection.Areas.Count to count the different areas selected.
Then I can work out how many columns each area has b
icnt2 = Selection.Areas(icnt1).Columns.Count
then knowing what is selected I can copy it to the new sheet in order.
But the "deselected" column appears as a further Selection.area which
screws it up.
Is there a way to tell if a column is selected?
John


--

Dave Peterson