How to write a macro in Excel to add "x" amount of rows.?
-
I want to write a macro that will look at the last row used on a worksheet and add "x" amount of rows below the last used row where "x" is the result of a cell in another worksheet within the same spreadsheet. Example: Last row used on Sheet 1! is 206 and in row 208 I have a totals line. I want to add rows in between row 206 and 208 where the number of rows to add is derived from a subtotal formula in Sheet 2! cell a110. What would the code for this macro look like? Any help would be appreciated. Thanks.
-
Answer:
try this... Sub InsertRows() Dim NumberofRows, LastRow As Integer NumberofRows = Worksheets("Sheet2").Range("A110").Value LastRow = Worksheets("Sheet1").Range("A1"). _ End(xlDown).Row Rows(LastRow + 1 & ":" & LastRow + NumberofRows).Insert shift:=xlDown End Sub
Yahoo! Answers Visit the source
Other answers
try this... Sub InsertRows() Dim NumberofRows, LastRow As Integer NumberofRows = Worksheets("Sheet2").Range("A110").Value LastRow = Worksheets("Sheet1").Range("A1"). _ End(xlDown).Row Rows(LastRow + 1 & ":" & LastRow + NumberofRows).Insert shift:=xlDown End Sub
James
Related Q & A:
- How To Write A Resume?Best solution by Yahoo! Answers
- How To Write A Letter?Best solution by Yahoo! Answers
- How to write a parser in C?Best solution by Stack Overflow
- How to create a virtual file on mac OS X?Best solution by Super User
- How to write a persuasive letter to a bank?Best solution by wikihow.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.