Macro to enter rows while copying formulas

excelisland10

New Member
Joined
Jun 11, 2020
Messages
1
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi,

I’m kind of new to macros and having a hard time creating the following:

On my spreadsheet, I have three types of rows, let’s call them Type A, Type B, and Type C. I need a macro button that can do the following when I click it: First it asks the number of rows, I want to add and then it asks where to insert the new rows. For example, if I want to add four rows above row 275, I would enter 4 in the first prompt and 275 in the second.

I also need the different rows to contain different types of formulas. I was thinking of having templates for the three different rows (Type A, B, and C) on a different sheet and having the macro copying and pasting them based on this: the first row will always be Type A, any subsequent row will be Type B, and the last row will always be Type C. For example, with the macro above, I want to add 5 rows above row 300. So first prompt I will put in 5, then 300 in the second, and then I want the first inserted row to copy the formulas from the Type A row, rows 2-4 to have the formulas from Type B, and the fifth row to copy the formula from Type C. Also, keep in mind, the number of rows I want won’t always be five.

Any help on this would be greatly appreciated, please feel to ask questions if I made this too confusing.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hello excelisland10 and welcome to the forum. You could start this by breaking it down and not trying to do everything at once. Try the code below where you give it a row number and it then inserts 4 rows there. You can easily modify this code. Hope this helps get you started.

VBA Code:
Sub AddRows()
StartRow = InputBox("Enter Starting Row Number", "Start Row")

Rows(StartRow & ":" & StartRow + 4).Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,483
Messages
6,125,063
Members
449,206
Latest member
Healthydogs

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