+ Reply to Thread
Results 1 to 26 of 26

NEED HELP - Columns data matching and moving results to another cell

Hybrid View

  1. #1
    Registered User
    Join Date
    03-28-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    28

    NEED HELP - Columns data matching and moving results to another cell

    Hi, i will try to explain this as best as i can, the macro is to be used to match data from one column with the data from another column and move the matching results, i have tried to explain on the file attached.

    As it show in the file i need to match the skus from column F with the skus from column D however i want if there is a match all the data from column F G H I and J to move along the matching SKU cell on the Column D, sometimes will only be data in column F G and H, so its not a permanent thing to have as many columns to move along but the SKU column is the only one that will match, i hope this makes sense and i also hope the file will help. This is quite urgent as i have to match over 150K skus.

    kind regards and many thanks in advance.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: NEED HELP - Columns data matching and moving results to another cell

    You could use the following assuming SKU's comparing are on same line as per your file
    Sub moveData()
    Dim k As Long, ws1 As Worksheet
    'Change to sheet name
    Set ws1 = Worksheets("Sheet1")
    For k = 2 To ws1.Cells(Rows.Count, "F").End(xlUp).Row
    If ws1.Range("F" & k) = ws1.Range("D" & k) Then
    ws1.Range("F" & k).Resize(, 5).Cut
    ws1.Range("E" & k).Insert Shift:=xlToRight
    End If
    Next
    End Sub
    Hope this helps.
    Anthony
    Pack my box with five dozen liquor jugs
    PS: Remember to mark your questions as Solved once you are satisfied. Please rate the answer(s) by selecting the Star in the lower left next to the Triangle. It is appreciated?

  3. #3
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: NEED HELP - Columns data matching and moving results to another cell

    almost the same
    Sub ertert()
    Dim i&
    On Error Resume Next
    For i = 2 To Cells(Rows.Count, 4).End(xlUp).Row Step 8500 '*
        With Cells(i, 5).Resize(8500).SpecialCells(4)
            .FormulaR1C1 = "=IF(RC[-1]=RC[1],1,"""")"
            .SpecialCells(xlCellTypeFormulas, xlNumbers).Delete
            .SpecialCells(xlCellTypeFormulas).ClearContents
        End With
    Next i
    End Sub
    *I do not remember the maximum number of cells for the SpecialCells in Excel 2003 (9860 or 8960?), so used 8500.

  4. #4
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,685

    Re: NEED HELP - Columns data matching and moving results to another cell

    You can try this code also


    Sub Rearrange()
        
    Dim LR, TA As Integer
    LR = Range("A2").End(xlDown).Row
    
        For TA = 2 To LR
        
        If Cells(TA, "D") = Cells(TA, "F") Then
        Range("E" & TA).Delete Shift:=xlToLeft
        End If
        
        Next TA
    End Sub

  5. #5
    Registered User
    Join Date
    03-28-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: NEED HELP - Columns data matching and moving results to another cell

    hi,

    ive tried all this and none of them seam to work, i uploaded a real example of the data i want to match, in this sheet i want to match the data from column F with the data from column D and i want all the data from column G (Data 4) column H (DATA 5) to move along accordingly as well with column G. many thanks guys, im really looking forward to carry on trying your solutions as im hopeless with stuff like this, im also not sure if i should have the file saved any special way, im using office 2010.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    03-28-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: NEED HELP - Columns data matching and moving results to another cell

    on the post above "...from column F with the data from column D and i want all the data from column G (Data 4) column H (DATA 5) to move along accordingly as well with column G...." but i should have said at the end NOT column G but column F.

  7. #7
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: NEED HELP - Columns data matching and moving results to another cell

    The reason none of the code worked is because the data type in D is number and the data type in F is text. Try
    Sub moveData()
    Dim k As Long, ws1 As Worksheet
    'Change to sheet name
    Application.ScreenUpdating = False
    Set ws1 = Worksheets("Sheet1")
    For k = 2 To ws1.Cells(Rows.Count, "F").End(xlUp).Row
    If CLng(ws1.Range("F" & k)) = CLng(ws1.Range("D" & k)) Then
    ws1.Range("F" & k).Resize(, 3).Cut
    ws1.Range("E" & k).Insert Shift:=xlToRight
    End If
    Next
    Application.ScreenUpdating = True
    End Sub
    Do a backup as you cannot undo VBA code. I have assumed if F=D then cut F to H and move to Column E - I hope that's what you mean. Code in module 2
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    03-28-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: NEED HELP - Columns data matching and moving results to another cell

    hi, it only worked for the first 27 rows the remaining ones stayed the same and there were still more data to match, i also dont want to limit the columns to follow the match to 2 columns as there will be times where there will be more data columns, maybe im doing something wrong..

  9. #9
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: NEED HELP - Columns data matching and moving results to another cell

    From your example the matching SKU's were in the same row - do you want to match SKU from one row to another row? In last example Row 31 has 10332020 in Column D and and Row 33 has 10332020 = do you want these to match - your example had matches between Column D & F in same row. If you want to match different rows then how is the data to appear - what happens to the data in row 33? Does it get overwritten or does the existing data in row 33 have to be placed elsewhere?
    Could you upload a sample of how you want it to appear when matches are on different rows as this I assume is what you are talking about. Will there ever be multiple rows matching? If so how does that get handled. If you want to start matching different rows it would be easier to generate a new sheet with all the matches listed first and all the non matches listed below. Upload a sample based on the last workbook you uploaded. As I say it stopped at row 28 as the other matches are on different rows and you have not explained how you want this to be handled.

  10. #10
    Registered User
    Join Date
    03-28-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: NEED HELP - Columns data matching and moving results to another cell

    i understand what you mean now, i think it could work if you make the data to match 6 columns maximum and then allow 7 columns break from column D therefore the data wont overlap, do you think this would work?

  11. #11
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: NEED HELP - Columns data matching and moving results to another cell

    That could work however it is a little messy and still requires data to be swapped around. Will there every be more than 1 match? - if there will never be more than 1 match (i.e. the SKU only occurs ONCE in column D and ONCE in column F) then I would just swap the data in the rows. That way there is no spaces/empty rows - this all depends on if there is only ever one match possible. If the data in Column D can match multiple cells in Column F then I would recommend just creating a duplicate sheet with the data.

  12. #12
    Registered User
    Join Date
    03-28-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: NEED HELP - Columns data matching and moving results to another cell

    hi, yes there will only be one match, generally the sku number, can you please make the changes in the macro as i wont be able to do it.

    thanks again, you have been a great help.

  13. #13
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: NEED HELP - Columns data matching and moving results to another cell

    Try attached workbook - do a backup before running on real data. I am at work so have not had much time to test this well.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    03-28-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: NEED HELP - Columns data matching and moving results to another cell

    hi, that works great, is there any way the unmatched data would move to another sheet or another area in the sheet? that way would make it easier to copy the matched data, not to worry if it cant i can work like this, or even having the 6 column gap so all the matched data would be really easy to copy.

  15. #15
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: NEED HELP - Columns data matching and moving results to another cell

    In Sheet 2 you will get all the matches so you can copy the matching values easily and Sheet1 will just condense down to the non matching values. The final sheet is just a copy of the data I used for testing.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    03-28-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: NEED HELP - Columns data matching and moving results to another cell

    been trying to work with V2 workbook you sent me as the V3 gives an error, the V2 works with the data you have on it already but when i change the data and use it again it gives me a run time error 13 type mismatch, the same with the V3, does the cells need to be formatted in any way ? the columns data will always be different types, sometimes i want to match numbers, sometimes a mix of numbers and letters but i will only want to match column F data with the column D data, also important is sometimes i will have data on A B C and D or just on C and D or just on D the same with the columns F G H I and J, i will sometimes data on all of them and sometime just on some of them and as you know its only the data on F i want to match to column D but i will want all the data from the G H I and J to move along with column F (sometimes will only be F and G to move), also consider that sometimes not all the rows will have data on both sides to match and to be matched. i hope i make sence and thank yo uso much for your help, im lookng forward to hear from you all the way across in Australia.

    p.s im Portuguese and funny enough my sister also lives in Australia in Sidney :-)

  17. #17
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: NEED HELP - Columns data matching and moving results to another cell

    Could you upload a sample workbook with data where you are getting the error - it is not a complicated bit of code and unless I can see where error is occurring very hard to advise you. Just create a sample workbook with a few lines of data run the code and if the error occurs upload that sample workbook. Do not change the sheet names you are using - make sure everything is the same just make sure there is enough data in it to replicate the error. If you changed the sheet names from Sheet1 then you would get a different error so it will be the data type but it should work with any data as it treats the data as a string. Upload a sample and do not change sheet names or starting lines where data is - make sure you get the error with the sample workbook and upload it and I will fix it for you. If you do it ASAP I will do before I go to bed.

  18. #18
    Registered User
    Join Date
    03-28-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: NEED HELP - Columns data matching and moving results to another cell

    Dont really know why it says im my profile that im using excel 2003, im not! im using office 2010, im enclosing the sheet with the results i got with different data, does the cells need to be formatted in any way to make it work? i will have different type of data to match, sometimes will be numbers sometimes data or data and numbers together, the data in the other columns will be like that as well however i will only want to match the data from column F to the data in column D (and not the other way around, data from D to match data from F) also sometimes there will be empty cells and sometimes columns A B C will be used randomly (sometimes just C and D sometimes B C and D etc) and data on columns A B and C only matters when i get the results of the matching and copy it along with the others matching columns so they will never need to be moved unless they are copied along with the results to another sheet as you have done on V3, the same happens to data on columns G H I and J in the way there will be times where only 2 of them will be used and sometimes all 4, i hope im making sense, you have been a great help, i will look forward for your reply all the way from Australia

    p.s , im Portuguese but my sister also lives in Australia, Sidney

  19. #19
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: NEED HELP - Columns data matching and moving results to another cell

    The excel version makes no difference in this case - did you forget to upload a workbook? No - the cells do not need to be formatted in anyway and the copying as you want is not a problem. If you upload a workbook that would be great. As you see I am in Brisbane - about 1000km from Sydney and a long way from Portugal - was in Lisbon about 1 year ago - really nice place.

  20. #20
    Registered User
    Join Date
    03-28-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: NEED HELP - Columns data matching and moving results to another cell

    yes i did , sorry, here it goes
    Attached Files Attached Files

  21. #21
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: NEED HELP - Columns data matching and moving results to another cell

    I have removed the delete at the end - just make sure sheet2 has the data the way you want - as I said in previous post I did it quickly. I have added a routine to find the last row in the workbook as well since your data will vary. I will have to check in morning if there is any problems with this version. I have just created a matching list in Sheet2 for you. I will check in morning if needs adjustment.
    Attached Files Attached Files

  22. #22
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: NEED HELP - Columns data matching and moving results to another cell

    Did this do what you require? Do you want the delete section at the end to remove the empty rows after the matches are moved to second sheet? However if your problem is now solved could you please mark the thread as Solved: Click Thread Tools above your first post, select "Mark your thread as Solved". Or click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes. It would be much appreciated.

  23. #23
    Registered User
    Join Date
    03-28-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: NEED HELP - Columns data matching and moving results to another cell

    Hi, it all works fine, many thanks for your help, its been amazing.

  24. #24
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: NEED HELP - Columns data matching and moving results to another cell

    That's great - could you please change this thread to Solved - : Click Thread Tools above your first post, select "Mark your thread as Solved". Or click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes. It would be much appreciated.

  25. #25
    Registered User
    Join Date
    03-28-2011
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: NEED HELP - Columns data matching and moving results to another cell

    Hi again, i dont really want to be a pain but i just come with a situation where i needed 3 more data rows on each side, is that something quite simple to do? if so can you be kind enough to do it for me and then i will click on the Solved, many thanks once again.

  26. #26
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: NEED HELP - Columns data matching and moving results to another cell

    So if you have inserted 3 more data columns does that mean you are now comparing Column I value with Column G? ...if then match is found then copy Column A to G to Sheet 2 and copy Column I to Column P to Column H in sheet 2? If my assumptions are incorrect upload small sample with new data structure showing where data is to compare. If my assumptions correct then
    If Len(ws1.Range("I" & k)) > 0 Then
    Set fnRng = ws1.Columns(7).Find(ws1.Range("I" & k), ws1.Range("G2"), xlValues, xlWhole)
    If Not fnRng Is Nothing Then
    Set cmpCpy = ws1.Range("I" & k).Resize(, 8)
    Set fmCpy = ws1.Range("A" & fnRng.Row).Resize(, 7)
    cmpCpy.Cut ws2.Range("H" & ws2.Cells(Rows.Count, "H").End(xlUp).Row + 1)
    fmCpy.Cut ws2.Range("A" & ws2.Cells(Rows.Count, "H").End(xlUp).Row)
    Based on your description that would be my estimate of the changes required - if does not work then a small sample of data and I will change code for you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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