+ Reply to Thread
Results 1 to 11 of 11

Insert Rows

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Insert Rows

    Hello:

    I have excel sheet with name of Clients in Column B starting from cell B2 and goes on until B300
    I want to insert 2 rows in between each client and name those cell as A & B and format it to the right of the cell.

    Example as below:

    Cell B2 : John Doe
    B3 : Alen Smith
    B4 : Wes Barb

    change above to :

    B2 : John Doe
    B3 : A
    B4 : B
    B5 : Alen Smith
    B6 : A
    B7 : B
    B8 : Wes Barb
    B9 : A
    B10: B
    and so on..
    Please let me know if any questions.

    Thanks

    RM
    Last edited by rizmomin; 07-19-2012 at 08:51 PM.

  2. #2
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: Insert Rows

    If this is a one-time thing, you can just insert a column before B, number each name in sequence. Then create a similar numbered list with A's and a list with B's, then sort the entire list by sequence.

  3. #3
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Insert Rows

    Hello:

    I do not think that would work for me since i have 300 rows of clients and need to add rows inbetween client names.

    Please help with VB Code to perform the task.

    Thanks

    RM
    Last edited by rizmomin; 07-19-2012 at 04:48 PM.

  4. #4
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: Insert Rows

    Again, if this is a one-time thing, the method described above will work. If you need to do this repeatedly, do you need to retain formatting or formulas on the existing rows? Are there any criteria for including/excluding rows (totals, subtotals)?

  5. #5
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Insert Rows

    Hello:

    I think you are misunderstanding me.
    Please refer to attached excel sheet as example.
    This is showing just few customers in sheet1...overall i have over 350 customers.
    Sheet2 is what i need to achive for all customers.

    Please let me know if any questions.
    Thanks a lot for helping.
    Riz
    Attached Files Attached Files

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Insert Rows

    Hello Riz,

    I have added a button to "Sheet2" to run the macro below. This will copy the data, add the needed rows, and right align the two newly added rows for each entry.
    
    Sub AddRowsAndFormat()
    
        Dim Cell As Range
        Dim Data As Variant
        Dim DstRng As Range
        Dim r As Long
        Dim RngEnd As Range
        Dim SrcRng As Range
        
            Set SrcRng = Worksheets("Sheet1").Range("A1")
            Set DstRng = Worksheets("Sheet2").Range("A1")
            
                Set RngEnd = SrcRng.Parent.Cells(Rows.Count, SrcRng.Column).End(xlUp)
                If RngEnd.Row < SrcRng.Row Then Exit Sub
                
                Set SrcRng = SrcRng.Parent.Range(SrcRng, RngEnd).Resize(ColumnSize:=2)
                
                ReDim Data(1 To SrcRng.Rows.Count * 3, 1 To 2)
                
                Application.ScreenUpdating = False
                
                    For Each Cell In SrcRng.Columns(1).Cells
                        r = r + 1
                        Data(r, 1) = Cell
                        Data(r, 2) = Cell.Offset(0, 1)
                        Data(r + 1, 1) = ""
                        Data(r + 1, 2) = "Invoices Generated"
                        Data(r + 2, 1) = ""
                        Data(r + 2, 2) = "Invoices Paid"
                        r = r + 2
                    Next Cell
                    
                DstRng.Parent.Columns(1).EntireColumn.Clear
                DstRng.Parent.Columns(2).EntireColumn.Clear
                
                Set DstRng = DstRng.Resize(UBound(Data, 1), 2)
                DstRng.Value = Data
                
                For r = 1 To DstRng.Rows.Count Step 3
                    DstRng.Item(r + 1, 2).Resize(2, 1).HorizontalAlignment = xlHAlignRight
                Next r
                
                Application.ScreenUpdating = True
                
    End Sub
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  7. #7
    Forum Contributor
    Join Date
    03-21-2012
    Location
    Ho Chi Minh city
    MS-Off Ver
    Excel 2003
    Posts
    180

    Re: Insert Rows & column("A:A")

    PHP Code: 
    Option Explicit
    Sub gpeMacro
    ()
     
    Dim Cls As Range
     Dim Rws 
    As Long:                           Dim MyStr As String
     
     Columns
    ("A:A").Select:                     Selection.Insert Shift:=xlToRight
     Rws 
    Cells(Rows.Count"C").End(xlUp).Row
     Cells
    (Rws"A").Value "GPE.COM":         Cells(1"A").Value "GPE.COM"
     
     
    For Each Cls In Range("C2:C" Rws)
        
    MyStr "A" Cls.Row:                  Cls.Offset(, -2).Value MyStr
        With Cells
    (Rows.Count"A").End(xlUp).Offset(1)
            .
    Value MyStr "A":               .Offset(, 2).Value "A"
            
    .Offset(1).Value MyStr "B":     .Offset(12).Value "B"
            
    .Offset(, 2).Resize(2).HorizontalAlignment xlRight
        End With
     Next Cls
     Columns
    ("A:C").Select
     Selection
    .Sort Key1:=Range("A2"), Order1:=xlAscendingHeader:=xlYesOrderCustom:=1
     Columns
    ("A:A").Delete
    End Sub 
    Last edited by Sa DQ; 07-19-2012 at 08:54 PM.

  8. #8
    Forum Contributor wallyeye's Avatar
    Join Date
    05-06-2011
    Location
    Arizona
    MS-Off Ver
    Office 2010, 2007
    Posts
    308

    Re: Insert Rows & column("A:A")

    Genius Sa, exactly what I was talking about, I should have thought to do that in VBA.

  9. #9
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Insert Rows

    Hi Leith:

    This will work great for me...

    Thanks a lot

    Riz

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Insert Rows

    Hello Riz,

    You're welcome.

  11. #11
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    Re: Insert Rows

    Hi wallyeye:

    Thanks a lot

    Riz

+ 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