• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

Insert Row(s) in Excel Based on Condition

I'm looking for a way to set a Macro that will insert lines based upon the number that will be pulled into column C from a Data Scrape that will occur in an EXTRA! Session based upon Columns A&B. But also when it inserts the lines it will also copy the information in Columns A&B and set it into each inserted line.  Is this possible?
0
NYANBCNY32
Asked:
NYANBCNY32
  • 2
  • 2
1 Solution
 
Gregory MillerGeneral ManagerCommented:
Hmmm... Maybe you could post an example of the spreadsheet. That would help clarify your question.
0
 
NYANBCNY32Author Commented:
sure thing, attaching it now, ultimately there's going to be an unknown amount of data is A&B where this will need to be run, but C will have the amount of records that will need to have data pulled, so I figured it would be easier if macro could insert and copy the data to the lines to prep for this.
InsertExample.xlsx
0
 
Gregory MillerGeneral ManagerCommented:
Can you also show a mock up of how you are describing the data insert. I am going to be honest, I am not following your instructions on what you want to do.
0
 
FlysterCommented:
If you're looking to add the number of rows to match the value in column "C", this macro will do that:
Sub CopyRows()
Dim c, i, r, l As Integer

c = 0
i = Range("C2").Value
r = 2

  For rc = 1 To ActiveSheet.UsedRange.Rows.Count - 1
    If i > 1 Then
      For l = 1 To i - 1
        Rows(r + c).Select
        Selection.Copy
        Rows(r + c + 1).Select
        Selection.Insert Shift:=xlDown
        Application.CutCopyMode = False
        c = c + 1
      Next l
        i = Range("C" & r + c + 1).Value
      End If
    c = c + 1
  Next rc
End Sub

Open in new window

Flyster
0
 
NYANBCNY32Author Commented:
This worked perfect! Thank you!
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now