+ Reply to Thread
Results 1 to 2 of 2

Trying to make this Macro Apply to Every Populated Row??

Hybrid View

  1. #1
    Registered User
    Join Date
    06-11-2014
    Posts
    1

    Trying to make this Macro Apply to Every Populated Row??

    Currently this macro will insert a row above the highlighted row and copy and past data from the above row into the new row and populate the last cell in the second row with "Shipping". Is there any way to make this apply to all populated rows in an excel sheet? or even apply it to 20 or 30 at a time?

    Thank you in advance for any help!

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer

    Sub Macro1()
    '
    ' Macro1 Macro
    '
    ' Keyboard Shortcut: Ctrl+q
    
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        ActiveCell.Offset(-1, 0).Range("A1").Select
        Selection.Copy
        ActiveCell.Offset(1, 0).Range("A1").Select
        ActiveSheet.Paste
        ActiveCell.Offset(-1, 1).Range("A1").Select
        Application.CutCopyMode = False
        Selection.Copy
        ActiveCell.Offset(1, 0).Range("A1").Select
        ActiveSheet.Paste
        ActiveCell.Offset(-1, 1).Range("A1").Select
        Application.CutCopyMode = False
        Selection.Copy
        ActiveCell.Offset(1, 0).Range("A1").Select
        ActiveSheet.Paste
        ActiveCell.Offset(-1, 1).Range("A1").Select
        Application.CutCopyMode = False
        Selection.Copy
        ActiveCell.Offset(1, 0).Range("A1").Select
        ActiveSheet.Paste
        ActiveCell.Offset(-1, 1).Range("A1").Select
        Application.CutCopyMode = False
        Selection.Copy
        ActiveCell.Offset(1, -1).Range("A1").Select
        ActiveSheet.Paste
        ActiveCell.Offset(0, 3).Range("A1").Select
        Application.CutCopyMode = False
        ActiveCell.FormulaR1C1 = "Shipping"
        ActiveCell.Offset(10, -1).Range("A1").Select
    End Sub
    Last edited by 6StringJazzer; 06-11-2014 at 12:27 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Trying to make this Macro Apply to Every Populated Row??

    Assuming your headers are in row 1, try this:
    Sub copy_row()
    Dim x&, y&, i&, c As Long
    Dim arr As Variant
    Dim dat() As String
    With ActiveSheet.UsedRange
        arr = .Value
        c = UBound(arr, 2)
        ReDim dat(1 To 2 * UBound(arr, 1), 1 To c)
        For y = 1 To c
            dat(1, y) = arr(1, y)
        Next y
        For x = 2 To UBound(arr, 1)
            For i = 1 To 2
                For y = 1 To c
                    dat(x * 2 + i - 3, y) = arr(x, y)
                Next y
                If i = 2 Then dat(x * 2 + i - 3, c) = "Shipping"
            Next i
        Next x
    End With
    With Sheets.Add
        .Range("A1").Resize(UBound(dat, 1), c).Value = dat
        .Columns.AutoFit
    End With
    End Sub
    1. Include a sample workbook with an example of the result you want
    2. Use [CODE] and [FORMULA] wrappers for your VBA code or excel formulas
    3. If your question has been answered, mark the thread as SOLVED and click on the "Add Rep" star to thank whoever helped you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Make cells invisible until they are populated
    By Vegita_Z in forum Excel General
    Replies: 11
    Last Post: 06-05-2014, 11:33 PM
  2. [SOLVED] Apply Macro First UnprotectSheet After Apply Macro ProtectAgain Solved by : Sixthsense
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-02-2014, 05:32 AM
  3. [SOLVED] Make AutoSum Cell move down as rows are populated?
    By poof in forum Excel General
    Replies: 5
    Last Post: 04-30-2013, 04:02 PM
  4. need to make macro apply to each entry of a list and not just the first entry
    By SIFT-MS88 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-22-2010, 10:30 AM
  5. Replies: 1
    Last Post: 02-09-2005, 09:06 PM

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