+ Reply to Thread
Results 1 to 3 of 3

VB code to spreadsheet application

Hybrid View

Astuch VB code to spreadsheet... 12-19-2007, 12:26 PM
davesexcel Check this out... 12-19-2007, 12:32 PM
Astuch Thank you. 12-19-2007, 12:41 PM
  1. #1
    Registered User
    Join Date
    12-19-2007
    Posts
    13

    VB code to spreadsheet application

    Hello,

    My goal is to input code to add a blank row between pre-existing rows with data.

    example:
    A
    B
    C

    to

    A

    B

    C

    I have found some code to do the task - on a previous thread - but I lack the knowledge and experience in how to input the code to make it work.

    Could someone help me?

    Thank you.

    Sub InsertBlankRows()
    Const Rows2Insert As Integer = 1
    
    Dim lngCtr As Long
    Dim lngRows As Long
    Dim iStep As Integer
    
    iStep = Rows2Insert + 1
    lngRows = iStep * (ActiveCell.End(xlDown).Row - ActiveCell.Row)
    
    On Error GoTo errTrap
    For lngCtr = 1 To lngRows Step iStep
       ActiveCell.Offset(RowOffset:=lngCtr).Resize(RowSize:=Rows2Insert).EntireRow.Insert
    Next lngCtr
    Exit Sub
    errTrap:
       MsgBox _
          Title:="Incomplete Action", _
          Prompt:="Cannot continue inserting rows", _
          Buttons:=vbCritical + vbOKOnly
    End Sub

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525
    Quote Originally Posted by Astuch
    Hello,

    My goal is to input code to add a blank row between pre-existing rows with data.

    example:
    A
    B
    C

    to

    A

    B

    C

    I have found some code to do the task - on a previous thread - but I lack the knowledge and experience in how to input the code to make it work.

    Could someone help me?

    Thank you.

    Sub InsertBlankRows()
    Const Rows2Insert As Integer = 1
    
    Dim lngCtr As Long
    Dim lngRows As Long
    Dim iStep As Integer
    
    iStep = Rows2Insert + 1
    lngRows = iStep * (ActiveCell.End(xlDown).Row - ActiveCell.Row)
    
    On Error GoTo errTrap
    For lngCtr = 1 To lngRows Step iStep
       ActiveCell.Offset(RowOffset:=lngCtr).Resize(RowSize:=Rows2Insert).EntireRow.Insert
    Next lngCtr
    Exit Sub
    errTrap:
       MsgBox _
          Title:="Incomplete Action", _
          Prompt:="Cannot continue inserting rows", _
          Buttons:=vbCritical + vbOKOnly
    End Sub
    Check this out
    http://www.contextures.com/xlvba01.html#Regular

  3. #3
    Registered User
    Join Date
    12-19-2007
    Posts
    13

    Thank you.

    Thank you for your reply Dave.

+ Reply to Thread

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