VBA to insert rows

mc136355

New Member
Joined
Mar 20, 2018
Messages
36
Hi ive searched google to try and find answer to my problem but there are similar questions but dont know how to manipulate the vba to suit me.

My problem is i need to achieve the following
i enter a value into A1 e.g 10 and it would then goto the start of my table data say A16 and then copy the row of data 10 times creating 10 identical rows of data. Any help on this would be appreciated.

thanks MC
 
Yes, using the data from your post #18 , I get the same results. Now change your formula in cell B4 to =R6*S6, B5 =R7*S7 and tell me what you get...
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
DATEPRESC NOCUSTOMERSITE
#REF!043678123456789
00/01/190043678123456789CustA
01/08/2019123456789
CustA
SiteA

<colgroup><col style="mso-width-source:userset;mso-width-alt:3537;width:76pt" width="101"> <col style="mso-width-source:userset;mso-width-alt:3840;width:83pt" width="110"> <col style="mso-width-source:userset;mso-width-alt:3607;width:78pt" width="103"> <col style="mso-width-source:userset;mso-width-alt:2583;width:56pt" width="74"> </colgroup><tbody>
</tbody>

here is whats happening MC
 
Upvote 0
DATEPRESC NOCUSTOMERSITE
#REF!043678123456789
00/01/190043678123456789CustA
01/08/2019123456789CustASiteA

<tbody>
</tbody>

here is whats happening MC

Both my code and Akuini's codes returns the date correctly. Is the date the result of a formula or is it static.
 
Last edited:
Upvote 0
Hi

i apologise the date is a formula but i realise it needs to be absolute ref. i have =C2 should be =$C$2 OOps MC
 
Upvote 0
Are any of the codes working for you...


@Akuini - the fact that the OP was getting the date error without an absolute reference, reinforces what I was experiencing with the formula autofilling with changed references
 
Last edited:
Upvote 0
Before code
COUNT
=COUNTIF(F$15:F15,F15)

<colgroup><col style="mso-width-source:userset;mso-width-alt:4142;width:178pt" width="237"> </colgroup><tbody>
</tbody>

After code
COUNT
=COUNTIF(F15:F$16,F15)
=COUNTIF(F$16:F16,F16)
=COUNTIF(F$15:F17,F17)

<colgroup><col style="mso-width-source:userset;mso-width-alt:4142;width:178pt" width="237"> </colgroup><tbody>
</tbody>

This is the only problem i find. the countif just numbers the rows 1 to whatever. This is getting mixed up. MC
 
Upvote 0
Yes, using the data from your post #18 , I get the same results. Now change your formula in cell B4 to =R6*S6, B5 =R7*S7 and tell me what you get...


If column R:S is part of the table then formula in B4 stays the same, but if it isn't then the formula changes to =R4*S4
 
Upvote 0
Akuini the code that you have provided seams to resolve this issue. At the moment i cant seam to find any further issue. Thanks MC
 
Upvote 0
That is the answer then, as my formulas were referencing cells outside of the table.

However for my own benefit I am trying to write a solution that will have the desired result with references to non-table cells.
 
Upvote 0
Akuini the code that you have provided seams to resolve this issue. At the moment i cant seam to find any further issue. Thanks MC

Are you sure?
Actually I find my code produce the issue as you described at post #26
Please try this one:

Code:
Sub a1107749c()
'https://www.mrexcel.com/forum/excel-questions/1107749-vba-insert-rows.html

    Dim x As Long
    
    Application.ScreenUpdating = False
    x = Range("A1").Value

    With ActiveSheet.ListObjects("medline")
        .DataBodyRange.Rows("2:" & x + 1).Insert
        .DataBodyRange.Rows(1).Copy .DataBodyRange.Rows("2:" & x + 1)
    End With
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,431
Messages
6,119,457
Members
448,898
Latest member
drewmorgan128

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