+ Reply to Thread
Results 1 to 4 of 4

One line of Data duplicated into multiple lines changing values of some lines

Hybrid View

  1. #1
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: One line of Data duplicated into multiple lines changing values of some lines

    This macro meets your "RULES", but the results have a few more rows than your example results, I believe it is because all 3 sample rows have "YES" in column AY.

    Option Explicit
    Option Compare Text
    
    Sub CreateExtract()
    Dim LR As Long, Rw As Long, NR As Long
    Dim OrderNums As String
    Dim wsIN As Worksheet, wsOUT As Worksheet
    
    Set wsIN = ThisWorkbook.Sheets("Raw Data")
    Set wsOUT = ThisWorkbook.Sheets("Extract")
    
    LR = wsIN.Range("A" & wsIN.Rows.Count).End(xlUp).Row
    wsOUT.UsedRange.Offset(1).Clear
    NR = 2
    
    For Rw = 2 To LR
    'Back
        If InStr(wsIN.Range("AM" & Rw).Value, "B") > 0 Then
            wsIN.Rows(Rw).Copy wsOUT.Range("A" & NR)
            wsOUT.Range("AM" & NR).Value = "Back"
            NR = NR + 1
        End If
    'Round
        If InStr(wsIN.Range("AM" & Rw).Value, "R") > 0 Then
            wsIN.Rows(Rw).Copy wsOUT.Range("A" & NR)
            wsOUT.Range("AM" & NR).Value = "Round"
            NR = NR + 1
        End If
    'Site Clear (only 1 order number per Extract table)
        If InStr(OrderNums, wsIN.Range("E" & Rw).Value) = 0 Then
            wsIN.Rows(Rw).Copy wsOUT.Range("A" & NR)
            wsOUT.Range("AM" & NR).Value = "Site Clear"
            OrderNums = OrderNums & "," & wsIN.Range("E" & Rw).Value
            NR = NR + 1
        End If
    'Surplus
        If wsIN.Range("AY" & Rw).Value = "YES" Then
            wsIN.Rows(Rw).Copy wsOUT.Range("A" & NR)
            wsOUT.Range("AM" & NR).Value = "Surplus"
            NR = NR + 1
        End If
    'Dra Rep
        If wsIN.Range("BF" & Rw).Value = "YES" Then
            wsIN.Rows(Rw).Copy wsOUT.Range("A" & NR)
            wsOUT.Range("AM" & NR).Value = "Dra Rep"
            NR = NR + 1
        End If
    'Spec Sur
        If wsIN.Range("BH" & Rw).Value = "YES" Then
            wsIN.Rows(Rw).Copy wsOUT.Range("A" & NR)
            wsOUT.Range("AM" & NR).Value = "Spec Sur"
            NR = NR + 1
        End If
    Next Rw
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  2. #2
    Registered User
    Join Date
    03-26-2014
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: One line of Data duplicated into multiple lines changing values of some lines

    That's great, works brilliantly. However I can't see in the code how it deals with a "BR" and splits them to a B and an R? I can see a B to become back, and R to become Round, but somehow it works for the BR. Sorry just curious so I can learn from this. Its awesome though! Really appreciated

+ 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. Replies: 4
    Last Post: 08-27-2019, 02:40 PM
  2. How to combine data from multiple lines into one line
    By MikeDbes in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-03-2016, 04:34 AM
  3. add lines with changing formulas depending on lines in another worksheet
    By fragger224 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-27-2015, 05:15 AM
  4. Multiple lines of similar data to one single line
    By T_Van in forum Excel General
    Replies: 7
    Last Post: 02-27-2012, 06:03 PM
  5. Replies: 0
    Last Post: 02-09-2012, 11:53 AM
  6. Data on multiple lines needs to be put into 1 line
    By DMBeer41 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-22-2011, 11:58 AM
  7. Duplicated lines in a data table
    By kosciosco in forum Excel General
    Replies: 0
    Last Post: 06-08-2006, 12:29 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