![]() |
Insert a number of rows based on a value in a cell on active row
-------------------------------------------------------------------------------- Hey all. I am new to macros in excel. Hoping to find help. I have a worksheet, 3 columns and lets say 1000 rows. Column A is a beginning page number of a document, column B is its ending page number, and column C is the number of pages calculated by subtracting Bx - Ay and adding 1. Example: ... 1000 1001 1 1002 1005 4 1006 1007 2 1008 1008 1 ... I'd like to have a macro which would go line-by-line and insert an appropriate number of rows in between so I can flesh-out the ranges of values. Example result would be: 1000 1001 1 1002 1005 4 1006 1007 2 1008 1008 1 Any help would be greatly appreciated. -- iRocco ------------------------------------------------------------------------ iRocco's Profile: http://www.excelforum.com/member.php...o&userid=26147 View this thread: http://www.excelforum.com/showthread...hreadid=394734 |
Insert a number of rows based on a value in a cell on active row
Something like this?
Option Explicit Sub testme01() Dim FirstRow As Long Dim LastRow As Long Dim iRow As Long With ActiveSheet FirstRow = 2 'headers in row 1 LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row For iRow = LastRow To FirstRow Step -1 If IsNumeric(.Cells(iRow, "C").Value) Then .Rows(iRow + 1).Resize(.Cells(iRow, "C").Value).Insert End If Next iRow End With End Sub iRocco wrote: -------------------------------------------------------------------------------- Hey all. I am new to macros in excel. Hoping to find help. I have a worksheet, 3 columns and lets say 1000 rows. Column A is a beginning page number of a document, column B is its ending page number, and column C is the number of pages calculated by subtracting Bx - Ay and adding 1. Example: .. 1000 1001 1 1002 1005 4 1006 1007 2 1008 1008 1 .. I'd like to have a macro which would go line-by-line and insert an appropriate number of rows in between so I can flesh-out the ranges of values. Example result would be: 1000 1001 1 1002 1005 4 1006 1007 2 1008 1008 1 Any help would be greatly appreciated. -- iRocco ------------------------------------------------------------------------ iRocco's Profile: http://www.excelforum.com/member.php...o&userid=26147 View this thread: http://www.excelforum.com/showthread...hreadid=394734 -- Dave Peterson |
Insert a number of rows based on a value in a cell on active row
Thanks Dave. That's pretty awesome. Only two things: The files don' generally have header rows, and the page counts in column 3 ar inclusive of the beginning value, so the macro would need to subtract from the value in column C to determine how many rows to add -- iRocc ----------------------------------------------------------------------- iRocco's Profile: http://www.excelforum.com/member.php...fo&userid=2614 View this thread: http://www.excelforum.com/showthread.php?threadid=39473 |
Insert a number of rows based on a value in a cell on active row
Glad you got it working after the tweaks.
iRocco wrote: Thanks Dave. That's pretty awesome. Only two things: The files don't generally have header rows, and the page counts in column 3 are inclusive of the beginning value, so the macro would need to subtract 1 from the value in column C to determine how many rows to add. -- iRocco ------------------------------------------------------------------------ iRocco's Profile: http://www.excelforum.com/member.php...o&userid=26147 View this thread: http://www.excelforum.com/showthread...hreadid=394734 -- Dave Peterson |
All times are GMT +1. The time now is 07:05 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com