Paste range to first column, then next blank column

horizonflame

Board Regular
Joined
Sep 27, 2018
Messages
172
Hi All,

I have found my formula for pasting a copied range to the next blank column, but need some help if the next blank column is the first column in the sheet. With my current formula it pastes to column B not A.

Sheets("DataRaw").Select
Application.Goto Reference:="R2C1:R7000C2,R2C7:R7000C7"
Selection.Copy

Sheets("DatesRaw").Range("A3").End(xlToLeft).Offset(0, 1).PasteSpecial xlValues
Application.CutCopyMode = False
Many thanks :)
 
Last edited:

Some videos you may like

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Mentor82

Active Member
Joined
Dec 30, 2018
Messages
307
Hi,
How about this?

Code:
DIM LastCol&
Dim OffsetNo&
Sheets("DataRaw").Select
Application.Goto Reference:="R2C1:R7000C2,R2C7:R7000C7"
Selection.Copy

LastCol=Sheets("DatesRaw").Range("A3").End(xlToLeft).Column
If LastCol = 1 and Sheets("DatesRaw").Range("A1")="" then
    OffsetNo=0
Else
    OffsetNo=1
End if
Sheets("DatesRaw").Range("A3").End(xlToLeft).Offset(0, OffsetNo).PasteSpecial xlValues
Application.CutCopyMode = False
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,903
Office Version
365
Platform
Windows
This line
Code:
Sheets("DatesRaw").Range("A3").End(xlToLeft).Offset(0, 1).PasteSpecial xlValues
will paste into B3 regardless of how many columns have data.
Will row 3 always have data?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,903
Office Version
365
Platform
Windows
In that case try
Code:
With Sheets("DatesRaw")
   If .Cells(3, 1) = "" Then
      .Cells(3, 1).PasteSpecial xlPasteValues
   Else
      .Cells(3, Columns.Count).End(xlToLeft).Offset(, 1).PasteSpecial xlPasteValues
   End If
End With
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,903
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Mentor82

Active Member
Joined
Dec 30, 2018
Messages
307
My pleasure. I'm glad we could help you. Thansk for you feedback :)
 

Watch MrExcel Video

Forum statistics

Threads
1,102,778
Messages
5,488,821
Members
407,658
Latest member
Arias610

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top