Consulting

Results 1 to 3 of 3

Thread: VBA code for inserting blank row in between the data points

  1. #1
    VBAX Newbie shekar's Avatar
    Joined
    Nov 2012
    Location
    india
    Posts
    3
    Location

    Post VBA code for inserting blank row in between the data points

    Hi All,

    I have huge excel file which contains lot of data , i want find particular data point and insert blnk row above the data point.
    my data as follows

    1 Sales Order
    2 minute
    3 Two
    4 second
    5 Three
    6 Sales Order
    7 minute
    8 Two
    9 second
    10 Three
    11 Sales Order
    12 minute
    13 Two
    14 second
    15 Three
    16 Sales Order
    17 minute
    18 Two
    19 second
    20 Three

    here i want find Sales order and above that i want insert blank row ......i have 15000 data points like this..

  2. #2
    VBAX Regular GreenDR's Avatar
    Joined
    Oct 2012
    Location
    India
    Posts
    25
    Location
    [vba]rcount = Application.WorksheetFunction.CountA(Range("A:A")) 'get the number of rows

    For r = 1 To rcount 'for each row
    If Range("A" & r).Value = "Sales Order" Then 'check for your criteria
    Application.CutCopyMode = False 'clear the clipboard just to make sure you dont insert some data
    Rows(r & ":" & r).Select 'select the row
    Selection.Insert Shift:=xlDown 'insert row
    r = r + 1
    End If
    Next r[/vba]
    GreenDR

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Just an observation:
    Application.WorksheetFunction.CountA(Range("A:A"))
    will not return a true row count where there are already blank rows (eg because the macro has been run before). Try:
    ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
    or:
    ActiveSheet.Range("A" & .Cells.SpecialCells(xlCellTypeLastCell).Row).End(xlUp).Row
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

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