Excel VBA - Alternative to Copy/Paste with xlToRight xlDown

NigelG5

New Member
Joined
Jan 30, 2017
Messages
4
I am trying to simplify the VBA below as there's too many selects and with the array of data being copied from one sheet to the other as the sheets get larger in size, I want to reduce the overhead and increase the speed it executes. It currently works, but isn't the cleanest.

The "TODAYS_DATA" tab contains the output of an Oracle SQL extraction that has been imported into Excel. What I want to do, is take that tabs content (from A2 across to the end and then down to capture the whole sheet), then paste it at the bottom of the tens of thousands of rows that exist in the "HISTORIC_DATA" tab already. I can then save the file and repeat this each day.

As I say, whilst this works, I am aware that there's no need to select cells and copy/cut/paste in this way is best avoided.

Code:
Sheets("TODAYS_DATA").Select
    Range("A2").Select   ' Using A2 as no need to copy of the heading row
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Cut
    'Paste that copied data from the last working day and paste it into the Historic_Data tab
    Sheets("HISTORIC_DATA").Select
    Range("A1").End(xlDown).Offset(1, 0).Select
    ActiveSheet.Paste
    Range("A1").Select
I have seen this as an alternative, but cannot get it to work no matter how I try and shoehorn it into what I already have.


Code:
Range(ActiveCell, Cells(ActiveCell.End(xlDown).Row, ActiveCell.End(xlToRight).Column)).Value
Any pointers would be good as trying to tidy up my code as I go along.

Thanks all :)
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
11,278
Office Version
2013
Platform
Windows
this would copy your data over.

Code:
Sub t()
Sheets("TODAYS_DATA").UsedRange.Offset(1).Copy Sheets("HISTORIC_DATA").Cells(Rows.Count, 1).End(xlUp)(2)
End Sub
 

NigelG5

New Member
Joined
Jan 30, 2017
Messages
4
this would copy your data over.

Code:
Sub t()
Sheets("TODAYS_DATA").UsedRange.Offset(1).Copy Sheets("HISTORIC_DATA").Cells(Rows.Count, 1).End(xlUp)(2)
End Sub
Thank you for that, it's certainly more streamlined than my original attempt and understand what that's all doing :)
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
11,278
Office Version
2013
Platform
Windows
Thank you for that, it's certainly more streamlined than my original attempt and understand what that's all doing :)
You're welcome,
Regards, JLG
 

CoraG

New Member
Joined
Aug 30, 2018
Messages
31
Code:
ActiveSheet.Range(ActiveCell, Range(ActiveCell).End(xlDown).End(xlToRight)).Select
 

Forum statistics

Threads
1,082,102
Messages
5,363,146
Members
400,720
Latest member
Pettel

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top