Results 1 to 6 of 6

Insert multiple rows depending on cell value

Threaded View

AR-51 Insert multiple rows... 03-02-2013, 08:59 PM
AR-51 Re: Insert multiple rows... 03-03-2013, 12:35 AM
AR-51 Re: Insert multiple rows... 03-03-2013, 01:11 AM
AR-51 Re: Insert multiple rows... 03-03-2013, 01:54 AM
event21 Re: Insert multiple rows... 03-03-2013, 03:28 AM
AR-51 Re: Insert multiple rows... 03-03-2013, 04:18 AM
  1. #1
    Registered User
    Join Date
    04-16-2012
    Location
    Space
    MS-Off Ver
    Excel 2010
    Posts
    14

    Insert multiple rows depending on cell value

    Hi all,
    I'm trying to insert multiple rows in a spreadsheet. The number of rows inserted is based on the cell value - 1.
    I'm able to change the number of rows inserted, but the number if fixed. I want the number to change depending on the value in column B.

    Thanks,

    Sub InsertRows()
    
    Dim lastCll As Long
    Dim cllValu As Long
    Dim i As Long
    Dim y As Long
    Dim x As String
    Dim Rnum As Long
    
    x = "Select"
    y = 1
    Rnum = cllValu - 1
    
    ' find last used cell in Column B
      lastCll = Cells(Rows.Count, "B").End(xlUp).Row
    
     ' get value of  last used cell in column B
      cllValu = Cells(lastCll, 2).Value
    
     ' insert rows by looping from bottom
      For i = lastCll To 2 Step -1
      ' if cell value is not equal to x insert a row
         If Cells(i, 1).Value <> x Then
      ' Next cell value
           cllValu = Cells(i, 2).Value
           Rows(i + 1).Resize(2).Insert
    '       Resize (.Value - 1)
           
         End If
      Next i
    
    End Sub
    Column A Column B
    Name Value
    456 1
    1
    454 1
    Select 3
    158 1
    Select 1
    865 1
    546 2
    948 3
    Select 4
    556 1
    642 2
    Select 3
    545 1
    Last edited by AR-51; 03-03-2013 at 04:06 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1