Hi!
I did a slight gambit, but I believe it brings the desired result.
As it is not possible to adjust the print configuration to print two columns, my idea was to create an auxiliary tab in which the shopping list is copied and printed as desired.
Follows the code:
Sub ImprimeLista()
'Imprime Lista do Mercado
Dim BlocPrint As Range
Dim FirstRow As Integer
Dim LastRow As Integer
Dim LastCol As Integer
Dim W As Worksheet
Dim WB As Worksheet
Application.DisplayAlerts = False
Sheets("Compras").Select
Cells(1, 1).Select
LastCol = ActiveSheet.Cells(4, 1).End(xlToRight).Column
FirstRow = Selection.Row
LastRow = Cells(Rows.Count, LastCol).End(xlUp).Row
'Adiciona uma nova aba e copia a tabela para ela
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "Impressão"
Set WB = Sheets("Impressão")
Set W = Sheets("Compras")
W.Select
'Seleciona a primeira metade
Set BlocPrint = W.Range(Cells(FirstRow, 1), Cells((LastRow / 2), LastCol))
BlocPrint.Select
Selection.Copy
WB.Select
WB.Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False
Application.CutCopyMode = False
'Seleciona a segunda metade
W.Select
Set BlocPrint = W.Range(Cells((LastRow / 2), 1), Cells((LastRow), LastCol))
BlocPrint.Select
Selection.Copy
WB.Select
WB.Range("G4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False
Application.CutCopyMode = False
'Coloca um cabeçalho na segunda coluna
WB.Range("A1:E3").Select
Selection.Copy
WB.Range("G1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A1:E1").Select
'Ajeita as colunas com produtos
WB.Range("A:A").EntireColumn.AutoFit
WB.Range("G:G").EntireColumn.AutoFit
WB.Columns(6).ColumnWidth = 2
'Configura a impressão
With ActiveSheet.PageSetup
WB.Select
WB.Range("A:G").Select
' .Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
Selection.PrintOut Copies:=1, Collate:=True
Range("A1").Select
End With
'Seleciona a planilha Compras e exclui a planilha Impressão
W.Select
W.Range("A1").Select
WB.Delete
Application.DisplayAlerts = True
End Sub
The end result was this: https://www.sendspace.com/file/6psv97
I hope you solve.
Hi Bautto! How are you? Please could you insert an image showing how your spreadsheet is structured, indicating, mainly, what is the last line filled in so I can help you? Thank you!
– Andréa Aline
Hello, Andrea. Follow the link to the archive.
– Bautto
It has 2 spreadsheets, the first (Notary) is the data entry and the second (Purchases) is the one I need to print, which summarizes the items to be purchased. Thank you for your interest. https://www.sendspace.com/file/ivezqi
– Bautto
Hi! I tested the code on the spreadsheet you sent me and the table was printed on a single page. I tested it twice: in the first I did not change the default settings of the print and in the second I changed and in both cases the result was the same. Were you expecting a different result? https://www.sendspace.com/file/zula7n
– Andréa Aline
The print comes out on a single page. What I want is that it comes out in two columns, because in one it is very reduced the print, making it difficult to read. I’m trying to do a routine to split the printing, for example, print the first 60 lines in one column and the rest in another, but I’m finding it difficult to configure the printer by VBA.
– Bautto