VBA Insert row instead of copy

0 votes

I'm trying to run before I can crawl. I have pieced together this code, but I need it to Insert at row 24, not copy.

Dim sh4 As Worksheet, sh5 As Worksheet, lr As Long, rng As Range
Set sh4 = Sheets("est")
Set sh5 = Sheets("gaf letter")
lr = sh4.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh4.Range("a1:a" & lr)
rng.EntireRow.Copy sh5.Rows("24:24")

I've attempted using .Insert, but it comes up with Method Insert of object Range Failed. The code works fine if I wanted to just copy, but I need it to insert and shift the remaining rows below it, down.

Jan 14 in Others by Kithuzzz
• 27,740 points
53 views

1 answer to this question.

0 votes

Try this:

Option Explicit ' declare all variables

Sub InsertRows()

    Dim sh4 As Worksheet, sh5 As Worksheet
    Dim lr As Long, rng As Range
    Set sh4 = Sheets("est")
    Set sh5 = Sheets("gaf letter")
    
    Application.ScreenUpdating = False
    With sh4
        lr = .Cells(.Rows.Count, 1).End(xlUp).Row
        Set rng = .Rows("1:" & lr)
        rng.Copy
        sh5.Rows(24).Insert shift:=xlDown
    End With
    Application.ScreenUpdating = True
    Application.CutCopyMode = False

End Sub
answered Jan 14 by narikkadan
• 51,240 points

Related Questions In Others

0 votes
0 answers

how to get another copy of my cert

Oct 1, 2019 in Others by Loletha
• 120 points
209 views
0 votes
2 answers

How to copy a formula horizontally within a table using Excel VBA?

Hi so basically, create an adjacent column ...READ MORE

answered Feb 16, 2022 in Others by Edureka
• 13,640 points
274 views
0 votes
1 answer

How to copy title of WP post dynamically to focus keyword field in Yoast SEO?

$title = get_the_title(); $args = array('posts_per_page' => -1, ...READ MORE

answered Feb 24, 2022 in Others by narikkadan
• 51,240 points
344 views
0 votes
1 answer

Excel VBA to change background image of shape by clicking on shape

You need to keep track of what ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 51,240 points
446 views
0 votes
1 answer

How to insert a picture into Excel at a specified cell position with VBA

Try this: With xlApp.ActiveSheet.Pictures.Insert(PicPath) With ...READ MORE

answered Oct 24, 2022 in Others by narikkadan
• 51,240 points
397 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
522 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
2,382 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 22,940 points
110 views
0 votes
1 answer

How to insert a new row in the specified cell only, of Excel sheet using c#?

I have this worksheet with a matrix ...READ MORE

answered Nov 24, 2022 in Others by narikkadan
• 51,240 points
219 views
0 votes
1 answer

Copy the time to the next row of another column

Try this: Sub CopyCurrentTime() Dim currentRow As Integer currentRow = ...READ MORE

answered 1 day ago in Others by narikkadan
• 51,240 points
24 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP