How to Copy Current Cell Address to Other Location in Excel?


Generally, in Excel, we can copy the content of a cell easily just by using the copy and paste function. But have you ever tried to copy the cell address of one cell from another? We can use the steps mentioned in this. Even though we can complete the task simply by using formulas, there are times when we need to use some interesting methods with the VBA application.

Read this tutorial to learn how we can copy the current cell address to another location in Excel using the VBA application. We can copy the current cell address to other locations using the VB code mentioned in this tutorial.

Copy Current Cell Address to Other Location in Excel

Here we will first open the VBA application, insert a module, and finally run the code to complete the task. Let us look at a simple procedure for copying the current cell address to another location in Excel using the VBA application.

Step 1

Let us consider a new Excel sheet, and right-click on the sheet name and select View Code to open the VBA application.

Right click > View code

Then, in the VBA application, click on insert and select module, then type the following program code in the text box as shown in the image given below.

Insert > Module

Program

Sub AddressCopy()
'Updated By Nirmal
    Dim xSRg As Range
    Dim xDRg As Range
    On Error Resume Next
    Set xSRg = Application.InputBox("Select cell(s) to copy its address:", "Copy cell address", Selection.Address, , , , , 8)
    If xSRg Is Nothing Then Exit Sub
    Set xDRg = Application.InputBox("Select a cell to paste:", "Copy cell address", , , , , , 8)
    If xDRg Is Nothing Then Exit Sub
    xDRg(1).Value = xSRg.Address
End Sub

Step 2

Then save the sheet as a macro-enabled workbook, click F5 to run the code, select the cell address or addresses you want to copy, and click OK, as shown in the below image.

Step 3

Then select the cell where you want to paste your result and click OK, as shown in the below image.

Conclusion

In this tutorial, we used a simple example to demonstrate how we can copy the current cell address to another location in Excel.

Updated on: 07-Mar-2023

337 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements