May 15 2023 05:53 AM
Hello there
1. i am not able to print those selected areas. When i want to print whole document get printed. Any solution for specific cell printing.
2. How can i fixed this sheet size where i can use it any computer it Won't change. I made this with custom margin. Please help.
May 16 2023 01:41 PM
Excel does not have a built-in feature to directly print specific non-contiguous cells or rows.
However, there are workarounds you can try:
Sub PrintSpecificCellsPreview()
Dim PrintRange As Range
Dim Cell As Range
' Set the range of cells to be printed
Set PrintRange = Range("A1,B3,D5") ' Update with your desired cell references
' Create a new worksheet for printing
Dim PrintSheet As Worksheet
Set PrintSheet = ThisWorkbook.Worksheets.Add
' Copy the selected cells to the printing worksheet
PrintRange.Copy PrintSheet.Range("A1")
' Display print preview
PrintSheet.PrintPreview
' Prompt the user to confirm printing
Dim Confirmation As Integer
Confirmation = MsgBox("Do you want to print the selected cells?", vbYesNo + vbQuestion, "Print Confirmation")
' If user confirms, print the copied cells
If Confirmation = vbYes Then
PrintSheet.PrintOut
End If
' Delete the printing worksheet after printing
Application.DisplayAlerts = False
PrintSheet.Delete
Application.DisplayAlerts = True
End Sub
To use this code:
This VBA code will create a new temporary worksheet, copy the selected cells to that worksheet, display a print preview, prompt the user to confirm printing, and if confirmed, print the copied cells. After printing, the temporary worksheet will be deleted.