Copy a selection of data and offset 1 cell

kyriakos kyriakou

New Member
Joined
Mar 28, 2020
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I want to make a macro that goes to another tab find all the cells that have context in it in column A, copy them (without copying the row 1 as i have the titles there) and paste them to a different tab.

Here is my code.

Sheets("Source_previous month").Select
Application.Goto Reference:="R9999C1"
Selection.End(xlUp).Select
Range(Selection, Selection.End(xlUp)).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.Copy
Sheets("Pivot").Select
Range("A2").Select
ActiveSheet.Paste



My problem is that, when i offset, it looses the selection, so with this code, it just copy one cell.


Thanks in advance
 

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.
How about
VBA Code:
   With Sheets("Source_previous month")
      .Range("A2", .Range("A" & Rows.Count).End(xlUp)).Copy Sheets("Pivot").Range("A2")
   End With
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
And if you have some more minutes and can help :) got another one question.

Now i copied my data using the above code. If i want it to write in B cells, "opening", how do you suggest should i do it

Just to write in the cell opening.

Thanks in advance
 
Upvote 0
Ok, how about
VBA Code:
   With Sheets("Source_previous month")
      With .Range("A2", .Range("A" & Rows.Count).End(xlUp))
         .Copy Sheets("Pivot").Range("A2")
         Sheets("Pivot").Range("B2").Resize(.Count).Value = "Opening"
      End With
   End With
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,917
Members
449,093
Latest member
dbomb1414

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