Solved

Insert Row(s) in Excel Based on Condition

Posted on 2013-12-15
5
387 Views
Last Modified: 2013-12-15
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
Comment
Question by:NYANBCNY32
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 11

Expert Comment

by:Gregory Miller
ID: 39720160
Hmmm... Maybe you could post an example of the spreadsheet. That would help clarify your question.
0
 

Author Comment

by:NYANBCNY32
ID: 39720177
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
 
LVL 11

Expert Comment

by:Gregory Miller
ID: 39720195
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
 
LVL 22

Accepted Solution

by:
Flyster earned 500 total points
ID: 39720345
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
 

Author Closing Comment

by:NYANBCNY32
ID: 39720437
This worked perfect! Thank you!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question