Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7531773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:15:47+00:00 2026-05-30T05:15:47+00:00

The code below is trying to paste the selected range (passed as rng )

  • 0

The code below is trying to paste the selected range (passed as rng) to the end of the worksheet.

It works if there are two rows already present (A1, A2).

Sub copyRow(rng As Range, ws As Worksheet)
    Dim newRange As Range
    Set newRange = ws.Range("A1").End(xlDown).Offset(1, 0)
    rng.Copy
    newRange.PasteSpecial (xlPasteAll)
End Sub

If A1 and A2 are present and you call this method 100 times, it inserts 100 rows after them.

If no rows are present or only A1, it just overwrites A2. I could see Excel write on the same row (overwrite).

Appears something to do with how xlDown calculates if there are less than 2 rows.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:15:48+00:00Added an answer on May 30, 2026 at 5:15 am

    Sorry but I do not agree with Michael’s answer.

    End(xlDown) is the VBA equivalent of clicking Ctrl+Down.

    Try Ctrl+Down with

    • an empty column
    • a column with a value in row 1 but no other
    • values in rows 1 and 2
    • values in rows 1, 2, 3, 7, 8, 9, 13, 14 and 15

    This will give you an idea of all the different rows, Ctrl+Down might take you to.

    Set newRange = ws.Range("A1").End(xlDown).End(xlDown).End(xlUp).Offset(1, 0) does not necessarily take you to the last used row plus 1.

    I am surprised Set newRange = ws.Range("A1").End(xlDown).Offset(1, 0) worked with an empty column. Range("A1").End(xlDown) would take you to the bottom row of the sheet then .Offset(1, 0) would try to take you off the sheet.

    Consider:

    Dim RowLast As Long
    
    RowLast = ws.Cells(Rows.Count, "A").End(xlUp).Row
    
    • If column A is empty, RowLast will be set to 1.
    • If A1 has a value but no other cells have values, RowLast will be set to 1.
    • If a number of cells in column A have values, RowLast will be set to the bottom row with a value.
    • If you have a value in the final row, it will be ignored.
    • If you have a value in the final two rows, RowLast will be set to Rows.Count – 1.

    I assume you do not have values in the borrom rows. If you do not care if row 1 is left blank with an empty column, then:

    RowLast = ws.Cells(Rows.Count, "A").End(xlUp).Row
    Set NewRange = ws.Cells(RowLast + 1, "A")
    

    should give the desired result regardless of the current contents of sheet ws.

    If you do care about row 1 being left blank, experimenting with Ctrl+Down and Ctrl+Up will give you an understanding of the effect of different combinations of values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the code below i`m trying to read a list of selected projects and
I have a plot (sample code pasted below) that I am trying to add
In the code below I'm trying to load some images and put them in
Afternoon all, Using the code below I'm trying to load what is render by
The code below is what I am trying to use in order to get
I'm trying to use the code below to send messages via System.Net.Mail and am
I am trying to run the code below but it keeps locking up my
I am trying to port the code below to mootools 1.1 code but am
The code below is (hopefully) a minimized testcase of my original problem. I'm trying
Note my code below. I am trying to figure out why my data is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.