
Private Sub CommandButton1_Click()
Dim wb As Workbook
Dim wsDati As Worksheet, wsStamp As Worksheet
Dim x As Long
Dim rngC As Range
Set wb = ThisWorkbook
Set wsDati = wb.Worksheets("Dati")
Set wsStamp = wb.Worksheets("Stampa")
'puliamo foglio stampa
With wsStamp
x = .Range("A" & .Rows.Count).End(xlUp).Row + 1
.Range("A3:F" & x).ClearContents
End With
With wsDati
x = .Range("A" & .Rows.Count).End(xlUp).Row
Set rngC = .Range("A2:A" & x)
End With
'copiamo le colonne utili
With rngC
.Offset(, 10).Copy wsStamp.Cells(3, 1)
.Offset(, 18).Resize(, 5).Copy wsStamp.Cells(3, 2)
End With
Set rngC = Nothing
'ordiniamole in ordine alfabetico
With wsStamp
x = .Range("A" & .Rows.Count).End(xlUp).Row
Set rngC = .Range("A3:F" & x)
rngC.Sort Key1:=rngC.Cells(1, 2), order1:=xlAscending
End With
Set rngC = Nothing
Set wsDati = Nothing
Set wsStamp = Nothing
Set wb = Nothing
End Sub
|
Sub stampa()
k = Range("a65536").End(xlUp).Row 'conta le righe occupare
Rows("2:" & k & "").Sort Key1:=Range("B2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal 'ordina le righe in base alla colonna b
Columns("l:r").Hidden = True 'nasconde le colonne dalla L alla R
ActiveSheet.PageSetup.PrintArea = "k2:w" & k & "" 'imposta l'area di stampa
Application.Dialogs(xlDialogPrint).Show 'mostra finestra di stampa
Columns().Hidden = False 'mostra le colonne nascoste
ActiveSheet.PageSetup.PrintArea = "" 'elimina l'area di stampa
Rows("2:" & k & "").Sort Key1:=Range("a2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal 'ordina le righe in base alla colonna a
'riportando la tabella allo stato iniziale
End Sub
|
Dim K as long
K = Range("A" & Rows.Count).End(xlUp).Row |
