Copy data from different sheet to another sheet using activecell offset

urubag

New Member
Joined
Aug 17, 2021
Messages
20
Office Version
  1. 365
Platform
  1. Windows
Hi All,

Please note I already have a code that works but I would like to do it faster.

VBA Code:
Dim X1, X2 as worksheet

Set X1 = Sheets("DataBase Hierarchy")
Set X2 = Sheets("Tool")

    X1.Select
    ActiveCell.Offset(0, -1).Copy
    X2.Select
    ActiveCell.Offset(0, 1).PasteSpecial xlPasteValues

I was trying to do something like this but not sure if is possible.

VBA Code:
Dim X1, X2 as worksheet

Set X1 = Sheets("DataBase Hierarchy")
Set X2 = Sheets("Tool")

X2.ActiveCell.Offset(0, 1).Value = X1.ActiveCell.Offset(0, -1).Value

The idea is to copy the data from activecell offset into another one in activecell Offset.

Appreciate your response.
Regards
Andres
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I think the issue is that you can really only have one ActiveCell, and it is dependent upon whatever is the ActiveSheet at that point in time.
So I don't think you can have two ActiveCells at the exact same time on different sheets, because only one of those sheet can be the ActiveSheet at that point in time!
 
Upvote 0
Code:
Dim X1, X2 as worksheet
If you do it like above, X1 is dimensioned as Variant.
In this case, it should be like so
Code:
Dim X1 As Worksheet, X2 as Worksheet

Is the 2nd ActiveCell (X1.ActiveCell) meant to be the same address of the first ActiveCell (X2.ActiveCell)?
Or is it meant to be the selected cell in that sheet before you changed sheets?
 
Upvote 0
Change Sheet references as required

If Sheet2 is your Active Sheet
Code:
Sub One_Possibility()
Dim X1 As Worksheet, X2 As Worksheet
Dim ActC As String
Set X1 = Sheets("Sheet1")
Set X2 = Sheets("Sheet2")
ActC = ActiveCell.Address
    ActiveCell.Offset(0, 1).Value = X1.Range(ActC).Offset(0, -1).Value
End Sub
If Sheet1 is your Active Sheet
Code:
Sub Another_Possibility()
Dim X1 As Worksheet, X2 As Worksheet
Dim ActC As String
Set X1 = Sheets("Sheet1")
Set X2 = Sheets("Sheet2")
ActC = ActiveCell.Address
    X2.Range(ActC).Offset(0, 1).Value = ActiveCell.Offset(0, -1).Value
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,139
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top