+ Reply to Thread
Results 1 to 7 of 7

Copy cells if arguments match

Hybrid View

zaopunk Copy cells if arguments match 04-14-2015, 08:18 PM
JOHN H. DAVIS Re: Copy cells if arguments... 04-15-2015, 09:00 AM
zaopunk Re: Copy cells if arguments... 04-16-2015, 10:35 PM
protonLeah Re: Copy cells if arguments... 04-16-2015, 10:39 PM
zaopunk Re: Copy cells if arguments... 05-14-2015, 09:58 PM
zaopunk Re: Copy cells if arguments... 05-14-2015, 11:32 PM
JOHN H. DAVIS Re: Copy cells if arguments... 05-15-2015, 06:32 AM
  1. #1
    Registered User
    Join Date
    04-14-2015
    Location
    Iowa
    MS-Off Ver
    2010
    Posts
    4

    Copy cells if arguments match

    Downloading an order_export.csv For each order I get multiple rows, one for each item ordered, but my dropoff location is only on the first row (column AT), I need to have the correct drop off that corresponds to the same order number, column A, before I can send it to my label maker.

    So what I need to do is check that A3 matches A2 AND check that AT3 is empty, if true I need to copy AT2 to AT3, and continue down the rows until hitting empty on column A.
    I also need to do this with another column, but I figured I would start with one.

    I uploaded the file so people could see exactly what I'm talking about.

    https://drive.google.com/file/d/0BxM...ew?usp=sharing

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy cells if arguments match

    Maybe:

    Sub zaopunk()
    Dim i As Long
    For i = 3 To Range("A2").End(xlDown).Row Step 2
        If Cells(i, "A") = Cells(i - 1, "A") Then
            If Cells(i, "AT") = "" Then Cells(i, "AT") = Cells(i - 1, "AT")
        End If
    Next i
    End Sub

  3. #3
    Registered User
    Join Date
    04-14-2015
    Location
    Iowa
    MS-Off Ver
    2010
    Posts
    4

    Re: Copy cells if arguments match

    So How would I put this into a macro then? Sorry, very green when it comes to Excel. Thank you for the fast response.

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,936

    Re: Copy cells if arguments match

    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button
    Ben Van Johnson

  5. #5
    Registered User
    Join Date
    04-14-2015
    Location
    Iowa
    MS-Off Ver
    2010
    Posts
    4

    Re: Copy cells if arguments match

    Alright, I got it to run. (Sorry, laptop went down on me after you guys replied!) when I ran the macro, it seems like it "sort of" worked. A couple lines got modified correctly, but most did not. Looking at the loop, if I understand it correctly, it should loop until it reaches a blank cell in column A correct?

  6. #6
    Registered User
    Join Date
    04-14-2015
    Location
    Iowa
    MS-Off Ver
    2010
    Posts
    4

    Re: Copy cells if arguments match

    Ok, so I got that working, and added my code to change another column in the same loop, my final challenge is to look at my Q column, which contains the quantity of the items ordered, and IF it is > 1 THEN copy the entire row, and paste it into newly inserted rows for however many over 1 the quantity was.
    Example

    Josh - Smith - Soda - 1
    John - Doe - Banana - 3
    Tony - Brown - Cake - 1

    Would need to become

    Josh - Smith - Soda - 1
    John - Doe - Banana - 3
    John - Doe - Banana - 3
    John - Doe - Banana - 3
    Tony - Brown - Cake - 1


    My code thus far is:
    Sub prepLabels()
    Dim i As Long
    For i = 3 To Range("A2").End(xlDown).Row Step 1
    If Cells(i, "A") = Cells(i - 1, "A") Then
    If Cells(i, "AT") = "" Then Cells(i, "AT") = Cells(i - 1, "AT")
    If Cells(i, "Y") = "" Then Cells(i, "Y") = Cells(i - 1, "Y")
    If Cells(i, "Q") > 1 Then
    ActiveCell.EntireRow.Select
    Selection.Copy
    Selection.Insert Shift:=xlDown
    End If
    End If
    Next i
    End Sub

    But obviously I failed at something, as my first row simply replicates 7 times or something.
    Any help would be great!

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copy cells if arguments match

    Try:

    Sub zaopunk()
    Dim i As Long, y As Long
    For i = 3 To Range("A2").End(xlDown).Row
    If Cells(i, "A") = Cells(i - 1, "A") Then
    If Cells(i, "AT") = "" Then Cells(i, "AT") = Cells(i - 1, "AT")
    If Cells(i, "Y") = "" Then Cells(i, "Y") = Cells(i - 1, "Y")
    End If
    Next i
    For i = Range("A2").End(xlDown).Row To 3 Step -1
    If Cells(i, "Q") > 1 Then
        y = Cells(i, "Q").Value
        Cells(i, "D").Value = y
        Rows(i).Copy
        Rows(i).Offset(1).Resize(y - 1).Insert
    End If
    Next i
    
    End Sub

+ 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. Sumif with index and match is returning too many arguments
    By jollyfella in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-02-2014, 10:45 AM
  2. Work Schedule Help - Index & Match Arguments
    By cy83rn3rd in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-14-2013, 04:03 AM
  3. Error using MATCH formula with LARGE and IF arguments
    By CMTR in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 04-10-2013, 10:57 AM
  4. [SOLVED] Match one cell with another, if match found copy adjacent cells
    By Xiophoid in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-07-2013, 05:50 AM
  5. Match Function arguments
    By Stan Altshuller in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-11-2005, 05:06 PM

Tags for this Thread

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