Forum Discussion
amnair1345
May 15, 2023Copper Contributor
Print specific cell value from excel sheet.
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.
- NikolinoDEGold Contributor
Excel does not have a built-in feature to directly print specific non-contiguous cells or rows.
However, there are workarounds you can try:
- Copy and Paste to a New Sheet: If you have non-contiguous cells or rows that you want to print, you can copy and paste them into a new sheet. Select the specific cells or rows you want to print, right-click and choose "Copy". Then, create a new worksheet, right-click on cell A1 in the new sheet, and choose "Paste". Once the selected cells are pasted in the new sheet, you can go to the "File" tab, click "Print", and choose to print the entire sheet.
- Use Filters: If you have a large dataset and want to print specific rows based on certain criteria, you can use Excel's filtering feature. Apply filters to your data, filter the rows based on the desired criteria, and then print the filtered data. This allows you to print only the rows that match your criteria.
- You can modify the previous VBA code to include a print preview before printing the specific cells.Here is the VBA Code:
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:
- Press Alt + F11 to open the VBA Editor in Excel.
- Insert a new module by clicking on "Insert" > "Module".
- Copy and paste the above code into the module.
- Update the PrintRange variable with the desired range of cells you want to print. For example, Range("A1,B3,D5") represents cells A1, B3, and D5. You can adjust this range as per your requirements.
- Close the VBA Editor.
- Run the macro by pressing Alt + F8, selecting the "PrintSpecificCellsPreview" macro, and clicking the "Run" button.
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.