How to Copy a Cell to Clipboard with VBA Code

Copying a cell with a single click can save time and effort compared to using the traditional copy and paste method. This is particularly useful if you frequently need to copy data from a particular cell or range of cells. With the automatic copy feature, you can avoid the risk of accidentally copying the wrong data or overwriting existing data in your worksheet. This post provides a tip on one-click copying in Excel via VBA code.

One-Click Copy by Excel VBA Code

If you are not familiar with the VBA code, you can use the following VBA code to copy the value of a cell to the clipboard with a single click:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.Count = 1 Then
        If Not Application.Intersect(Target, Range("A1:B10")) Is Nothing Then 
            Selection.Copy 
        End If
    End If
End Sub

In this code, “Worksheet_SelectionChange” is a built-in event in Excel VBA that is triggered whenever a cell is selected in the worksheet.

The “If” statement checks if only one cell is selected, so that the code only runs when a single cell is clicked.

The “Application.Intersect” function is used to check if the selected cell is within the specified range (A1:B10 in this example). If the selected cell is within the range, then the value of the selected cell is copied using the “Selection.Copy” method.

Here are the complete steps to use this code in your Excel workbook:

Step1: Press Alt + F11 to open the Visual Basic Editor. Or click the Visual Basic of Developer tab in the ribbon.

How to One-Click Copy a Cell Automatically by Single Click in Excel 1.png

Step2: In the Visual Basic Editor window, select the worksheet where you want to enable the copy action.

Step3: Right-click the worksheet and insert module by select “Insert” -> “Module” in the menu.

How to One-Click Copy a Cell Automatically by Single Click in Excel 2.png

Step4: Copy and paste the code above into the code window.

How to One-Click Copy a Cell Automatically by Single Click in Excel 3.png

Step5: Save the workbook and close the Visual Basic Editor.

Now, when you click on any cell in the worksheet, its value will be copied to the clipboard automatically. Select a cell where you want to paste the copied cell, press Ctrl+V to paste the content saved in the cell.

If you want to remove the restriction on one cell, you can remove the “if” statement about checking that a cell is selected. You can use the following VBA code to copy a range by single click/select.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Not Application.Intersect(Target, Range("A1:B10")) Is Nothing Then 
            Selection.Copy 
        End If
End Sub

How to Always Return the Value from the Cell above in Excel

Suppose you have a simple formula “=A1+1000” in cell A2 that references the cell above it, A1. If you insert a new row above row 2, the formula in A2 will not automatically update to reference the new cell A2, which still references to A1.

Before inserting a new row:

How to Always Get the Value from the Cell

After inserting a new row:

How to Always Get the Value from the Cell

Similarly, if you delete row 2, the formula in A3 will not automatically update to reference the cell above it, which is now A1. And #REF displays because B2=B2+1000 is impossible.

Before deleting Row 2:

How to Always Get the Value from the Cell

After deleting Row2:

How to Always Get the Value from the Cell

One way to avoid the above two problems and always get the value from above cell when inserting or deleting rows in Excel is to use a simple formula with Excel INDIRECT function and Excel ADDRESS function. This post introduces these two Excel functions and provides a formula to get the cell value above the selected cell when inserting or deleting rows.

EXCEL INDIRECT Function and ADDRESS Function

The Excel INDIRECT function is used to return a reference to a cell or range of cells based on a text string that represents the cell reference. This allows you to create dynamic formulas and references that change based on the contents of other cells or the result of other calculations.

The Excel ADDRESS function is used to return the cell reference as a text string based on a specified row and column number.

To combine the bove two Excel functions, we can get a dynamic cell reference in the formula which can help us always get the cell above the selected cell. In order to achieve it in this worksheet, we can use the formula “=INDIRECT(ADDRESS(ROW()-1,COLUMN())“, instead of using the reference address of the cell, such as “B1” to refer to.

Steps of Creating the Formula with INDIRECT Function and ADDRESS Function

Step1: Enter the following formula into Cell B2:

 =INDIRECT(ADDRESS(ROW()-1,COLUMN()))+1000" 

=INDIRECT(ADDRESS(ROW()-1,COLUMN()))” replaces the original data that is the cell reference.

How to Always Get the Value from the Cell

Step2: Drag down the formula to copy it to B3. The formula “=B2+1” is replaced by the new formula “=INDIRECT(ADDRESS(ROW()-1,COLUMN()))+1000” in B3, the result is the same.

How to Always Get the Value from the Cell

Step3: When inserting a new row above the selected cell, the formula will be recalculated and the nested function ADDRESS(ROW()-1,COLUMN()) always indicates to the cell above the selected cell.

How to Always Get the Value from the Cell

Note that if you have new data in new row above the cell when inserting a row, the formula will always points to the new position just above the current cell.

How to Always Get the Value from the Cell

How to Copy Cells Data with Column Widths in Excel

If you have a spreadsheet with multiple columns that you need to copy, and you want to make sure that all columns maintain their original column widths after pasting to the destination, you can copy the column widths and apply them to other columns. This post will introduce two ways to copy and paste cell data with the same column width as the original data.

Read More: Copy and Paste Cell or Row Heights to Another in Excel

Create a table containing two columns with a width of “15” for column A and “20” for column B. In an open Excel worksheet, the default column width is 10. Now we want to copy them from the range A1:B6 to D1:E6, with the same dimensions after copying the table.

How to Copy Cells Data with Column Widths in Excel 1.png

Copy Column Widths via Paste Special Feature in Excel

To copy the width of a column or columns in Excel, you can follow these steps:

1. Select the columns whose widths you want to copy. In this example, select the range A1:B6.

How to Copy Cells Data with Column Widths in Excel 2.png

2. Press the “Ctrl+C” keys on your keyboard to copy the columns.

3. Select a cell or range where you want to apply the pasting with column widths. In this example, you can select cell D1 or range D1:E6 to paste the table.

How to Copy Cells Data with Column Widths in Excel 3.png

4. Right-click on the selection and choose “Paste Special” -> “Keep Source Column Width” from the context menu.

How to Copy Cells Data with Column Widths in Excel 4.png

After this step, the original table is copied and pasted to the destination D1:E6 with the column widths.

How to Copy Cells Data with Column Widths in Excel 5.png

Copy Column Widths via Format Painter Tool in Excel

The Format Painter tool can copy the selected row or column’s formatting and apply it to the selected row or columns. You can follow the steps below to copy column widths by Format Painter.

1. Select the columns whose width you want to copy. Click on the column index on the column header to select the entire column. In this example, hold down the mouse and select column indexes A and B by dragging the mouse, then these two columns are selected.

How to Copy Cells Data with Column Widths in Excel 5.png

2. Click on the “Format Painter” button in the “Clipboard” group on the “Home” tab of the Excel ribbon. This button looks like a paintbrush.

How to Copy Cells Data with Column Widths in Excel 7.png

3. Click on the column or columns where you want to apply the same widths. In this example, hold down the mouse and select the D and E column indexes by dragging the mouse so that these two columns are selected. This step will apply the copied width to the selected columns.

How to Copy Cells Data with Column Widths in Excel 7.png

4. You can then use the normal “Copy” and “Paste” functions to copy the cell values to the destination with the same column width as the source table.

How to Copy Cells Data with Column Widths in Excel 9

How to Copy and Paste Cell Data Including Row Height and Column Width in Excel

If we want to copy a cell with different size to another normal size cell, its content will not be fully displayed in the destination with the desired size. Copying data with cell dimensions, including row heights and column widths, will ensure that the pasted cells are the same size as the copied cells, which will help us check the data in the spreadsheet for a good and consistent table structure.

Read More: Copy and Paste Cell or Row Heights to Another in Excel

If we copy the cell only by traditional “Copy “and “Paste” features, only the cell value is copied to the destination.

How to Copy and Paste Cell Data Including Row Height and Column Width in Excel 1.png

Our goal is to copy and paste calls that include not only their cell values, but also cell dimensions, such as row height and column width. This post will show you the way to copy and paste cell with its row height and column width in Excel.

Copy and Paste Cell Row Height and Column Width via Excel Paste Special Feature and Format Painter Feature

In Excel worksheet, to copy and paste cell data including the cell row height and column width, you can follow these steps:

1. Select the cell or range of cells that you want to copy.

2. Right-click on the selected cell, select “Copy” in the menu. Or press “Ctrl + C” on your keyboard.

3. Select the destination cell or range of cells where you want to paste the copied data.

4. Right-click on the destination cell or range of cells and select “Paste Special” -> “Keep Source Column Widths” from the “Paste Special” menu.

How to Copy and Paste Cell Data Including Row Height and Column Width in Excel 2.png

After this step, column widths are applied to the selected cell or range of cells properly.

How to Copy and Paste Cell Data Including Row Height and Column Width in Excel 3.png

The following are the steps for copying the row height:

5. Click on the row number of the row that you want to copy the row height.

How to Copy and Paste Cell Data Including Row Height and Column Width in Excel 4.png

6. Click the Format Painter on the Home tab of the ribbon.

How to Copy and Paste Cell Data Including Row Height and Column Width in Excel 5.png

7. Click on the row number of the row that you want to apply the row height. Format Paint will apply the row height to the selected row.

How to Copy and Paste Cell Data Including Row Height and Column Width in Excel 6.png

Note: After copying the row height with the Format Paint tool, the font size is reduced to 12, which is the default font size when opening an Excel worksheet. This is because the default font size for row 1 is still 12 (cell A1 has a font size of 18), and when copying the row formatting, the default font size is applied to the selected row as well. So it is better to copy the row height first, and then copy the cell values while maintaining the

How to Copy and Paste Cell or Row Heights to Another in Excel

Sometimes we need to adjust the row heights in our worksheets to ensure that consistent row heights can make Excel spreadsheets look more organized and visually appealing. If the rows are not evenly sized, the data may not align properly and can make it difficult to read. In this post, we will introduce some ways to copy the row height in an Excel worksheet to another row.

Read More: Copy and Paste Cell Sizes to Another Worksheet or Workbook in Excel

Copy and Paste Row Heights via Copying the Row Height Value

You may have tried to copy the row heights through Excel’s special paste feature. There is no such option to paste the row heights, only the column widths included.

By checking the row height in Excel, you can copy the row height number and copy it to the row height when you adjust another row. You can do this by following these steps.

Step1: Select the row(s) whose height you want to check. You can do this by clicking on the row number on the left-hand side of the worksheet.

How to Copy and Paste Cell or Row Heights to Another in Excel 1.png

Step2: Right-click on the selected row(s) and click on “Row Height” in the context menu.

How to Copy and Paste Cell or Row Heights to Another in Excel 2.png

Step3: In the “Row Height” dialog box, the “Row height” field will display the row height. In this example, the row height is “60”, you can also change the row height in this dialog box if you need to.

Step4: Copy the “Row height” number and click “OK” to close the dialog box.

How to Copy and Paste Cell or Row Heights to Another in Excel 3.png

Step5: Select another row whose height you want to pasted the row height. Click on the row number to select the entire row.

Step6: Right-click on the selected row(s) and click on “Row Height” in the context menu. Before copying the row height, the current row height is displayed in row height field.

How to Copy and Paste Cell or Row Heights to Another in Excel 4.png

Step7: Press “Ctrl+V” to paste the row height value we copied from row 1.

How to Copy and Paste Cell or Row Heights to Another in Excel 5.png

After all above steps, row height is copied and applied to row 2 properly.

How to Copy and Paste Cell or Row Heights to Another in Excel 6.png

Copy and Paste Row Heights via Using the Format Painter

Another way to check the row height is to use the “Format Painter” tool. Here are the steps:

Step1: Click on the row number to select the row whose height you want to copy.

How to Copy and Paste Cell or Row Heights to Another in Excel 7.png

Step2: Click on the “Format Painter” button in the “Home” tab of the Excel ribbon.

How to Copy and Paste Cell or Row Heights to Another in Excel 8.png

Step3: Click on another row number to apply the copied row height. The height of the selected row will change to match the height of the copied row, allowing you to visually compare the two row heights.

How to Copy and Paste Cell or Row Heights to Another in Excel 9.png

Conclusion

In summary, checking row height can help make your Excel spreadsheets more visually appealing, easier to read, and more functional for various tasks such as printing, filtering, sorting, and merging cells. After reading the post, you can adjust your row heights in a more convenient and accurate way to keep them consistent.

How to Copy and Paste Cell Sizes to Another Worksheet or Workbook in Excel

If you have a table or worksheet where you have already set up the column widths and row heights to your desired dimensions, you can use the copy and paste technique to quickly apply the same sizes to other cells or ranges, or even other worksheets or workbooks. This can help maintain a consistent and professional appearance throughout the worksheet or workbook.

In this post, we introduced some ways to copy and paste cells to the destination in another worksheet or workbook by copying the column width or row height as well. Let’s get started.

Read More: Copy and Paste Cell or Row Heights to Another in Excel

Copy and Paste Cell Column Widths in Another Worksheet or Workbook

When copying a table to a location in another worksheet or workbook via the traditional copy and paste function, only the values are copied to the destination, without copying the formatting, style or size, etc.

If a table with wide column widths is copied to a location with only narrow column widths, the copied values are not fully displayed in the columns and we must manually adjust the column widths.

How to Copy and Paste Cell Sizes to Another Worksheet or Workbook in Excel

In fact, we can now paste the copied table via “Special Paste” -> “Function” and include the column width correctly.

Here are the steps.

Step1: Select the cells whose sizes you want to copy.

Step2: Right-click on the selected cells and choose “Copy” from the context menu, or press “Ctrl+C” on your keyboard.

Step3: Select the destination cells where you want to paste the sizes. You can select a single cell, a range of cells, or even an entire row or column.

Step4: Right-click on the destination cells and choose “Paste Special” -> “Keep Source Column Widths” from the context menu.

How to Copy and Paste Cell Sizes to Another Worksheet or Workbook in Excel

Or press “Ctrl+Alt+V” on your keyboard to open “Paste Special” dialog box, and check on “Column widths” checkbox, and click “OK” to apply the changes.

How to Copy and Paste Cell Sizes to Another Worksheet or Workbook in Excel

Copy and Paste Cell Column Widths and Row Heights in Another Worksheet or Workbook

When copying and pasting cells, there is no such a way to allow copying the row height. But we can still do it in a special way.

Here are the steps:

Step1. Open the worksheet that contains the table you want to copy.

Step2. Click on the worksheet tab at the bottom of the screen to activate it.

Step3. Click on the “Select All” button located at the top-left corner of the worksheet, where the column and row headers meet. This selects all cells in the worksheet.

How to Copy and Paste Cell Sizes to Another Worksheet or Workbook in Excel

Step4. Right-click on any selected cell and choose “Copy” from the context menu, or press “Ctrl + C” on your keyboard.

Step5. Click on the worksheet tab or workbook where you want to paste the copied cells.

Step6. Click on the “Select All” button, press “Ctrl + V” to copy all cells with cell sizes from source worksheet to the new worksheet. In this way, the column widths and row heights are copied correctly to their destinations in the desired dimensions.

How to Copy and Paste Cell Sizes to Another Worksheet or Workbook in Excel

How to Copy a Selected Range to New Workbook in Excel

If you work with large amounts of data in Excel, it is likely that you have needed to copy a selected range of cells to a new workbook at some point. While you can manually copy and paste the range, this process can be time-consuming and error-prone, especially if you need to repeat the task frequently.

Fortunately, there are several ways to automate the process of copying a selected range to a new workbook in Excel. In this post, we will introduce two methods to achieve this task – the first one is the manual method, and the second one is using VBA code with Application.InputBox to select the range.

Copy a Selected Range to a New Workbook Manually

If you want to copy a selected range to a new workbook manually in Excel , you can follow these steps:

Step1: Select the range of cells you want to copy.

How to copy a selected range to a new workbook in Excel1.png

Step2: Press Ctrl + C on your keyboard to copy the selected range.

Step3: Click on the File tab in the ribbon menu, then select New to create a new workbook.

Step4: In the new workbook, click on the first cell where you want to paste the copied range.

How to copy a selected range to a new workbook in Excel2.png

Step5: Press Ctrl + V on your keyboard to paste the copied range.

Copy a Selected Range to a New Workbook with VBA Code

You can also use the VBA Code to copy a selected range to a new workbook in Excel, it will use the Application.Inputbox function to select the range. Just do the below steps:

Step1: Open the Excel workbook that contains the range you want to copy.

Step2: Press Alt + F11 on your keyboard to open the Visual Basic Editor.

Step3: In the Visual Basic Editor, click on Insert from the top menu and select Module to insert a new module.

Step4: Copy and paste the VBA code provided in the module.

vba to copy a selected range to a new workbook in Excel1.png
Sub CopyRangeToNewWorkbook_excelgeek()
    Dim myRange As Range
    Dim newWorkbook As Workbook
    
    'Prompt user to select range to copy
    Set myRange = Application.InputBox(prompt:="Select the range to copy", Type:=8)
    
    'Create a new workbook
    Set newWorkbook = Workbooks.Add
    
    'Copy the selected range to the new workbook
    myRange.Copy Destination:=newWorkbook.Sheets(1).Range("A1")
    
    'Activate the new workbook
    newWorkbook.Activate
End Sub

Step5: Press F5 or Run from the top menu to run the macro.

vba to copy a selected range to a new workbook in Excel2.png

Step6: In the pop-up window, select the range you want to copy by clicking and dragging your mouse over the cells. Click on the OK button to start the macro.

vba to copy a selected range to a new workbook in Excel3.png

Step7: Excel will create a new workbook and copy the selected range to the new workbook.

vba to copy a selected range to a new workbook in Excel4.png

How to Save an Excel Table as Image in Excel

This tutorial will introduce three methods for saving an Excel table as an image in Excel: “Paste as picture”, “Paint tool”, and “VBA code“.

The Paste as picture method allows you to create a picture of a range that can be easily inserted into documents or presentations.

The Paint tool method uses the built-in Windows Paint program to save the selected range as an image.

The VBA code method automates the process of saving the selected range as an image using Visual Basic for Applications (VBA) code.

Save Table as Image using Paste as Picture

You can save an Excel table as an image using the “paste as picture” feature. Here are the steps:

Step1: Select the table that you want to save as an image.

How to Save an Excel Table as Image in Excel 1.png

Step2: Right-click on the selected cells and choose “Copy” from the context menu or press Ctrl+C on your keyboard.

How to Save an Excel Table as Image in Excel 2.png

Step3: select one destination cell to place the image.  Then click the Home tab, click on the drop-down menu list from the Paste option in the Clipboard group.  Click on the Picture option.

How to Save an Excel Table as Image in Excel3.png

Now you can simply copy the image and paste it to other application.

Save Table as Image using Paint Tool

You can save an Excel table as an image using the Paint tool in Windows. Here are the steps:

Step1: Select the table that you want to save as an image.

Step2: Right-click on the selected cells and choose “Copy” from the context menu or press Ctrl+C on your keyboard.

Step3: Open the Paint tool by typing “Paint” in the Windows search bar and selecting the app from the search results.

Step4: In Paint, choose “Paste” from the “Home” tab or press Ctrl+V on your keyboard to paste the copied table into the canvas.

How to Save an Excel Table as Image in Excel4.png

Step5: Choose “Save As” from the “File” menu and select the desired file format (e.g. JPEG, PNG, BMP, etc.).

How to Save an Excel Table as Image in Excel5.png

Step6: Enter a file name and choose a save location. Click “Save” to save the image.

How to Save an Excel Table as Image in Excel6.png

Save Table as Image with VBA Code in Excel

You can use VBA code in Excel to save a selected table as an image and prompt the user to select a destination to save the image. Just do the following steps:

Step1: Open your Excel workbook.

Step2: Press Alt + F11 to open the VBA editor.

Step3: In the VBA editor, select Insert from the menu bar, then choose Module to create a new module.

Step4: Copy the VBA code I provided and paste it into the new module. Save the workbook and close the VBA editor.

vba to Save an Excel Table as Image in Excel 1.png
Sub sleep(T As Single)
    Dim time1 As Single
    time1 = Timer
    Do
        DoEvents
    Loop While Timer - time1 < T
End Sub
Sub SaveTableAsImage_excelgeek()
    Dim tbl As Range
    Dim savePath As String, fileName As String, fileFormat As String
    Dim cht As ChartObject
      
    'Prompt the user to select the table to save as an image
    Set tbl = Application.InputBox("Select the table to save as an image:", Type:=8)

    tbl.CopyPicture xlScreen, xlPicture
 
     'prompt user for save location and file name
    savePath = Application.GetSaveAsFilename(InitialFileName:="table1", _
        FileFilter:="JPEG (*.jpg), *.jpg, PNG (*.png), *.png")
    If savePath = "False" Then Exit Sub ' exit if user clicks cancel
     
    'extract file name and format from save path
    fileName = Mid(savePath, InStrRev(savePath, "\") + 1)
    fileFormat = Mid(fileName, InStrRev(fileName, ".") + 1)
    fileName = Left(fileName, InStrRev(fileName, ".") - 1)
    
    
    'create temporary chart object, set dimensions to table dimensions, paste table inside, and save as image
    Set cht = ActiveSheet.ChartObjects.Add(0, 0, tbl.Width, tbl.Height)
    Call sleep(2)
    cht.Chart.Paste
    cht.Chart.Export savePath, fileFormat
    cht.Delete
    Application.CutCopyMode = False
    
End Sub

Step5: Press Alt + F8 to open the Macros dialog box. Select the SaveTableAsImage_excelgeek macro from the list and click the Run button.

vba to Save an Excel Table as Image in Excel 2.png

Step6: Select the table to save as an image.

vba to Save an Excel Table as Image in Excel 3.png

Step7: select one the location to place image.

vba to Save an Excel Table as Image in Excel 4.png

Step8: The picture will be saved into the selected location.

vba to Save an Excel Table as Image in Excel 5.png

Conclusion

There are several methods available for saving an Excel table as an image, each with its own advantages and limitations. The “Paste as picture” method is quick and easy, but may result in lower image quality. The “Paint tool” method provides greater control over image quality, but requires an extra step. The “VBA code” method offers the most automation and customization options, but may require some programming knowledge.

How to Copy and Paste Range or Chart object as Picture in Excel

This post will introduce two methods to copy and paste a range or chart object as a picture in Excel. The first method involves using Excel’s built-in “Copy as Picture” feature, while the second method uses VBA code to automate the process.

The VBA code method will select a range or chart object using Application.Inputbox function and choose a destination cell for the picture. The VBA code will then copy the range or chart object as a picture and paste it into the specified cell.

Copy and Paste Range or Chart object as Picture using Copy as Picture

You can use the “Copy as Picture” feature in Excel to copy a range or chart object as a picture. Here are the steps:

Step1: Select the range or chart object that you want to copy as a picture.

How to Copy and Paste Range or Chart object as Picture in Excel 1.png

Step2: Go to the “Home” tab in the Excel Ribbon. Click the drop-down arrow next to the “Copy” button in the “Clipboard” section. Select “Copy as Picture” from the drop-down menu. The Copy Picture dialog box will open.

How to Copy and Paste Range or Chart object as Picture in Excel 2.png

Step3: In the “Copy Picture” dialog box, select the Format as Picture, and select Appearance as shown on screen.

How to Copy and Paste Range or Chart object as Picture in Excel 3.png

Step4: Click the “OK” button to copy the range or chart object as a picture.You can paste the picture wherever you want by pressing “Ctrl + V” on the keyboard.

How to Copy and Paste Range or Chart object as Picture in Excel 4.png

Copy and Paste Range or Chart object as Picture with VBA Code

You can also use the VBA Code to copy a range or chart object and paste it in your Excel worksheet, just do the following steps:

Step1: Open your Excel workbook.

Step2: Press Alt + F11 to open the VBA editor.

Step3: In the VBA editor, select Insert from the menu bar, then choose Module to create a new module.

Step4: Copy the VBA code I provided and paste it into the new module. Save the workbook and close the VBA editor.

vba Copy and Paste Range or Chart object as Picture in Excel 12.png
Sub CopyAsPicture_excelgeek()
    Dim rng As Range
    Dim chartObj As ChartObject
    Dim destCell As Range
    
    'Prompt user to select range or chart object
    On Error Resume Next
    Set rng = Application.InputBox("Select a range or chart object to copy as picture", Type:=8)
    On Error GoTo 0
    
    'If user selects a range, copy it as picture
    If Not rng Is Nothing Then
        rng.CopyPicture xlScreen, xlPicture
        
        'Prompt user to select destination cell
        On Error Resume Next
        Set destCell = Application.InputBox("Select destination cell to place picture", Type:=8)
        On Error GoTo 0
        
        'If user selects a cell, paste the picture and adjust its size
        If Not destCell Is Nothing Then
            With destCell.Parent.Pictures.Paste
                .Left = destCell.Left
                .Top = destCell.Top
                .Width = rng.Width
                .Height = rng.Height
            End With
        End If
    'If user selects a chart object, copy it as picture
    ElseIf ActiveChart Is Nothing Then
        MsgBox "Please select a range or chart object."
    Else
        Set chartObj = ActiveSheet.ChartObjects(ActiveChart.Parent.Name)
        chartObj.Chart.Export Environ$("temp") & "\temp.png", "PNG"
        With destCell.Parent.Pictures.Insert(Environ$("temp") & "\temp.png")
            .Left = destCell.Left
            .Top = destCell.Top
            .Width = chartObj.Width
            .Height = chartObj.Height
        End With
        Kill Environ$("temp") & "\temp.png"
    End If
End Sub

Step5: Press Alt + F8 to open the Macros dialog box. Select the CopyAsPicture_excelhow macro from the list and click the Run button.

vba Copy and Paste Range or Chart object as Picture in Excel 13.png

Step6: Select the cell where you want to paste the picture.

vba Copy and Paste Range or Chart object as Picture in Excel 3.png

Step7: select one the destination cell to place picture.

Step8: The picture will be pasted into the selected cell.

vba Copy and Paste Range or Chart object as Picture in Excel 5.png

How to Convert Range to Image in Excel

This post will introduce you to two methods of converting a range of cells to an image in Excel. The method involves using the “Copy As Picture” feature in Excel and a VBA code to export the copied range as an image file.

Convert Cells Range to Image Using Copy as Picture Feature

If you want to convert a range of cells to an image in Microsoft Excel Spreadsheet, you can use the built-in “Copy As Picture” feature. Here are the steps:

Step1: Select the cells range that you want to convert to an image.

Step2: Press the “Ctrl + C” shortcut on your keyboard to copy the cells range to the clipboard.

How to convert cells range to image in Excel 1.png

Step3: Click on the “Home” tab in the ribbon. Click on the “Copy” dropdown arrow in the “Clipboard” group, and then select “Copy as Picture“. The Copy Picture dialog box will open.

How to convert cells range to image in Excel 2.png

Step4: In the “Copy Picture” dialog box, select the “As shown on screen” option and the “Picture” format. Click on the “OK” button.

How to convert cells range to image in Excel 3.png

Step5: Now you can paste the copied cells range as an image in another location. For example, you can open an image editor (such as Microsoft Paint), and press the “Ctrl” and “V” keys on your keyboard to paste the image.

How to convert cells range to image in Excel4.png

Convert Cells Range to Image with VBA Code

You can also use VBA code to automate the process of converting a range of cells to an image. Just do the following steps:

Step1: Open your workbook that contains the range of cells you want to convert to an image.

Step2: Press Alt + F11 to open the Visual Basic Editor.

Step3: In the Visual Basic Editor, click on Insert > Module to create a new module.

Step4: Copy the below VBA code and paste it into the new module.

vba to convert cells range to image in Excel 1.png
Sub ConvertRangeToImage_excelgeek()
    Dim MyChart As ChartObject
    Dim MyRange As Range
    Dim DestPath As String
    Dim FileName As String
    
    Set MyRange = Application.InputBox("Select the range of cells:", Type:=8)
    MyRange.CopyPicture xlScreen, xlPicture
    
    Set MyChart = ActiveSheet.ChartObjects.Add(0, 0, MyRange.Width, MyRange.Height)
    
    MyChart.Activate
    MyChart.Chart.Paste
    DestPath = Application.GetSaveAsFilename(InitialFileName:="MyImage", _
        FileFilter:="PNG Files (*.png), *.png, JPEG Files (*.jpg), *.jpg, GIF Files (*.gif), *.gif, BMP Files (*.bmp), *.bmp", _
        Title:="Save As")
    If DestPath <> "False" Then
        FileName = Mid(DestPath, InStrRev(DestPath, "\") + 1)
        MyChart.Chart.Export DestPath, Mid(DestPath, InStrRev(DestPath, ".") + 1)
    End If
    MyChart.Delete
End Sub

Step5: Save the module and close the Visual Basic Editor. Press Alt + F8 to open the Macro dialog box.Select the ConvertRangeToImage_excelgeek macro from the list of available macros and click Run.

vba to convert cells range to image in Excel 2.png

Step6: select the range of cells you want to convert to an image.

vba to convert cells range to image in Excel 3.png

Step7: The code will prompt you to choose the destination folder and image name for the converted image.

vba to convert cells range to image in Excel 4.png

Step8: Once you select the destination folder and image name, the code will export the range of cells as an image file in the selected format.

vba to convert cells range to image in Excel 5.png

Conclusion

 With the above methods, you can easily convert any range of cells in your Excel worksheet to a PNG, JPG or other image format, which can be useful for sharing data, creating reports, or including the data in a presentation.