How to copy cells and insert cells

jfisher387

New Member
Joined
Feb 9, 2024
Messages
4
Office Version
  1. 365
Platform
  1. Windows
It's been awhile since I have played with Excel VBA macros. I have spent the majority of my time playing with C# lately and I am having trouble recalling how to do somethings.
I want to copy a range of cells on another sheet, and insert that range to my active sheet. a certain number of times (based on integer in a cell)
1707494179004.png


VBA Code:
Sub ItemQty()
'
'Quotes
'
Dim ItemQty As Integer
Dim SubItemQty As Integer

ItemQty = ThisWorkbook.Worksheets("Quote Sheet").Range("K1").Value

For i = 1 To ItemQty
    Sheets("TemplateGrid").Range("A1:K12").Copy
    Sheets("Quote Sheet").Range("A16").Insert Shift:=xlDown
    Application.CutCopyMode = False
Next
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Tested your macro with plain data, works for me; what's your issue ?
 
Upvote 0
I get Runt-time error '9':
subscript out of range
it then highlights this line
VBA Code:
ItemQty = ThisWorkbook.Worksheets("Quote Sheet").Range("K1").Value
 
Upvote 0
oh. i did not have the macro code in the correct file? i copied my code, right clicked the worksheet tab and view code. then pasted and now it appears to work
 
Upvote 0
Solution
Glad having been of some help ;). All you had to do was scrape off a little rust :giggle:.
By the way, you probably need to mark this thread as [Solved].
 
Upvote 0

Forum statistics

Threads
1,215,084
Messages
6,123,029
Members
449,092
Latest member
ikke

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