+ Reply to Thread
Results 1 to 91 of 91

Sorting Data

  1. #1
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Sorting Data

    Hi,

    I was wondering if this is at all possible

    I have a vast amount of data that I import every month, the columns remain the same on each import. Its sales data with around 20 columns. I want to extract row data of Product Number, Quantity and Date, Then sort each part number line in a date order by month.
    Is this possible??

    The only issue is, I am awful at VB :s

  2. #2
    Forum Contributor
    Join Date
    01-05-2017
    Location
    New York
    MS-Off Ver
    Office 2016
    Posts
    206

    Re: Sorting Data

    The more you learn about excel, the less you will ask "Is this possible?"

    Anyway, are you able to upload a sample worksheet?

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    I have the attachement system working now, hang on will post and example
    Last edited by rustyh; 07-31-2017 at 04:44 PM.

  5. #5
    Forum Contributor
    Join Date
    01-05-2017
    Location
    New York
    MS-Off Ver
    Office 2016
    Posts
    206

    Re: Sorting Data

    It sounds like you need a PivotTable. Select the data and click insert --> PivotTable. Setting up the PivotTable is pretty straightforward.

  6. #6
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Please find attached example.

    Basically, I get sent a copy of date like this each month, which I manually extract and enter in to a Sales Forecast Tracker Sheet, in which I list out each row in Part Number Order and then Date (month) order so I can forecast sales each month

    Im looking for a more automated way to extract the Part Number, Measured Date, Quantity, and Unit Price for every Line, and them list them in order of first the Part Number as the master listing, then each set of part numbers to be in date order (mainly the month)
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    01-05-2017
    Location
    New York
    MS-Off Ver
    Office 2016
    Posts
    206

    Re: Sorting Data

    Press alt+F11, find your current workbook on the sidebar and click on it. Click insert --> Module. Then copy and paste the following code:

    Please Login or Register  to view this content.
    Close the VBA editor. You will need to save your workbook as a Macro-enabled Workbook.

    To run the macro, Click View --> Macros, then click on "Delete_and_Sort".


    (Credit https://stackoverflow.com/a/16598513)
    Last edited by Raphaelp; 07-31-2017 at 05:15 PM.

  8. #8
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Holy Mackrel, That was quick.

    It works a treat, amazing, thank you

    I just realised one thing when I ran it though, it errored out I believe as sometimes there is not a measured date (as it hasnt been loaded in to the system fully yet), therefore can you make it so its also keeps the Due Date column, but if there is no measured date in the measured date column, to instead use the due date colume instead (and highlight the row or cell to visually show that row is based on due date and not measured date.

    Sorry if that doesnt make sense

    One other thing as well, If in the comments column there is the word "RMA", can it just delete that row out of thr data set?

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    I added a Foretracker sheet but if you like this we can put it wherever you want:

    Please Login or Register  to view this content.
    *I guess I'm late to the party

  10. #10
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    What does that do sorry?

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    This:

    Data Range
    A
    B
    C
    D
    E
    1
    Part Nbr
    Measured Due Date
    Quantity Due
    Unit Price
    Currency
    2
    GT376553
    8/4/2017
    5
    65.24
    USD
    3
    GT376553
    8/9/2017
    37
    65.24
    USD
    4
    GT376553
    9/19/2017
    78
    65.24
    USD
    5
    GT376553
    10/7/2017
    29
    65.24
    USD
    6
    GT376553
    1/16/2018
    13
    65.24
    USD
    7
    KI1504-78T
    8/11/2017
    95
    109.35
    USD
    8
    KI1504-78T
    8/16/2017
    59
    109.35
    USD
    9
    KI1504-78T
    9/3/2017
    84
    109.35
    USD
    10
    KI1504-78T
    11/12/2017
    29
    109.35
    USD
    11
    KI1504-78T
    12/28/2017
    59
    109.35
    USD
    12
    UP819327
    8/5/2017
    52
    7.23
    USD
    13
    UP819327
    9/15/2017
    80
    7.23
    USD
    14
    UP819327
    11/12/2017
    16
    7.23
    USD
    15
    UP819327
    12/18/2017
    26
    7.23
    USD
    16
    UP819327
    2/18/2018
    49
    7.23
    USD

    *But you need to add a sheet named ForeTracker
    Last edited by xladept; 07-31-2017 at 05:54 PM.

  12. #12
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Is it possible to have it do the extra two steps as well?

    Ssometimes there is not a measured date (as it hasnt been loaded in to the system fully yet), therefore can you make it so its also keeps the Due Date column, but if there is no measured date in the measured date column, to instead use the due date colume instead (and highlight the row or cell to visually show that row is based on due date and not measured date.

    Also, If in the comments column there is the word "RMA", can it just delete that row out of thr data set?

  13. #13
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    I'm using the Measured Due Date Column - there are no other dates in the sample - This dumps the RMA:

    Please Login or Register  to view this content.
    Last edited by xladept; 07-31-2017 at 10:49 PM.

  14. #14
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Oh yes, sorry, I had removed alot of the data row.

    Attached is an updated example sheet, where in some cases there is no date in the measured date column. In such a case, I would like for it to default to the Due Date column for ordering, and if possible just highlight that row or cell in some way to I know its based on due date and not measure date (maybe a colour change)


    Also, I dont think the RMA code is working as required. Im limited in my knowledge of VBA, but I believe its because its looking for an actual value of "RMA". Instead, I'd like it to delete any rows where the comments cell has the word "RMA" in, even if its in a sentance
    Attached Files Attached Files
    Last edited by rustyh; 08-01-2017 at 05:06 AM.

  15. #15
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Try this - don't forget to add a sheet named ForeTracker first:

    Please Login or Register  to view this content.
    Last edited by xladept; 08-01-2017 at 01:02 PM. Reason: Added Color

  16. #16
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Works perfectly

    Thank you

  17. #17
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    You're welcome!

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  18. #18
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Just wondering, where you have put the columns as the column letter, incase the order gets changes in the future, can you replace the column letter with the header name

    for example
    wt.Range("Part Nbr" & r).Value = ws.Range("Part Nbr" & r).Value

  19. #19
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Well - you wouldn't want the output column to be the same as the input column - would you??

    I'll work on that assumption

  20. #20
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Not sure I follow you sorry?

  21. #21
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    two other questions actually,

    If ws.Range("X" & r).Value Like "*RMA*" Then
    On this line of code, if I want to add other words to delete the rows accordingly, so I just used & "*word*"

    Also, is it possible to rather than pull the due date across to the measured date in the output file, add the due date column and leave the due date in that column while sorting?

  22. #22
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Now it would be:

    Please Login or Register  to view this content.
    We could probably pull out the Due Date after the sort.

    This will find the correct columns but I don't know how to use the string notation:

    Please Login or Register  to view this content.
    Last edited by xladept; 08-01-2017 at 03:05 PM.

  23. #23
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    sorry to keep going on, but is there also a way of creating a new column next to the part number column, with an column called Internal Part Number, then applying a If statement to each row that that for example, IF Part Number = UP819327 then Internal Part Number = BC557, IF Part Number = GT376553 then Internal Part Number = BC375, IF Part Number = KI1504-78T then Internal Part Number = BC963....and so on

  24. #24
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Where is this Internal Part Number?

  25. #25
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Its not in the table, We assigned seperate internal part numbers to each of thos customer part numbers, but it wont be in the list of sales date as per the example. I could create a seperate sheet on the workbook though with all the cross referenced part number if that would help with a lookup element?

  26. #26
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Yeah - do that - I'll just use a dictionary

  27. #27
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    So the attached now has a cross reference sheet. So is it possible to lookup the part number, then in the output sheet that the previous code make, add two new columns and put in the "internal Part Number" and "Platform"?
    Attached Files Attached Files

  28. #28
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Well, it's working

    Please Login or Register  to view this content.

  29. #29
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Hi,

    Im just having a play with this, trying to add some extra code for some other tasks, hard to learn when you have never done much programming, but slowly figuring it out.

    I want to use the section of code that looks for the comment "RMA" and deletes the row, but instead I want to delete all rows that don't contain a specific string this time.

    Can you just explain how this section works --> If ws.Range(C & r)

  30. #30
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Please Login or Register  to view this content.

  31. #31
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Ok, so the X refers to the column number, but when I change it to a different column number, I cant seem to get it to delete those rows.

    For example. Say Column C has the words "Phone" and "Email" in, and I want to delete all the "Email" rows, I would change the code to,

    DumpRMA:
    If ws.Range(C & r).Value Like "*Email*" Then _
    ws.Rows(r).EntireRow.Delete Shift:=xlUp: GoTo DumpRMA

    But this doesn't seem to work?

    Likewise, If I want to keep all the rows with a certain value in, would I change the Like to IsNot?

  32. #32
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    If it's actually column C then:

    Please Login or Register  to view this content.
    Don't forget we defined the columns by their headers that's why I could use X sans quotes.

    Your code would work if, like in the program, you had
    Please Login or Register  to view this content.

  33. #33
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Is this the line that defines the columes?

    Dim H As String: H = "Part Nbr,Measured Due Date,Quantity Due,Unit Price,Due Date,Comments"

    If so, how does it define what headers belong to what column number?

    (Sorry for the really basic questions)

  34. #34
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Please Login or Register  to view this content.

  35. #35
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Really not understanding that

    Am I following correctly?.....

    Q = Split(H, ",") - Loads the String defined in H, one by one in to variable Q, so first Q=Part Nbr

    Set F = ws.Rows(1).Find(Q(n), , , xlWhole) = Set variable F as the value defined in Q, and assigns it to what column is given in the n values above. So first F = Part Nbr for Column A

    S = Replace(F.Address, "$", ""): - Replaces the header for column A in the new sheet with the header defined in variable F

    It then repeats for every value of n

    ?

  36. #36
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Q = Split(H, ",") - Loads the String defined in H, one by one in to variable Q, so first Q=Part Nbr

    Set F = ws.Rows(1).Find(Q(n), , , xlWhole) = Set variable F as the value defined in Q, and assigns it to what column is given in the n values above. So first F = Part Nbr for Column A

    S = Replace(F.Address, "$", ""): - Replaces the header for column A in the new sheet with the header defined in variable F

    It then repeats for every value of n

    ?
    Sort of:

    Q = Split(H, ",") - Loads the String defined in H, one by one in to variable Q, so first Q=Part Nbr

    Q is an array each element of which is one of the headers

    Set F = ws.Rows(1).Find(Q(n), , , xlWhole) = Set variable F as the value defined in Q, and assigns it to what column is given in the n values above. So first F = Part Nbr for Column A

    F is the Range where the header is found

    S = Replace(F.Address, "$", ""): - Replaces the header for column A in the new sheet with the header defined in variable F

    The address is absolute - so we strip out the $ signs -
    And know that the column literal will be that string minus the last character
    which, since it's row 1 is just a one


    It then repeats for every value of n

    ? Yep

  37. #37
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    How do I best write that part mentioned above, regarding wanting to keep all the rows with a certain value in

    Ive Tried,

    If Not ws.Range(X & r).Value Like "*Email*" Then _
    Rows(r).EntireRow.Delete Shift:=xlUp: GoTo DumpRMA

    and

    If ws.Range(X & r).Value Like "*Email*" Then _
    Else Rows(r).EntireRow.Delete Shift:=xlUp: GoTo DumpRMA


    but both of those seem to crash excel and I have to close it via task manager

  38. #38
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Something like this:

    Please Login or Register  to view this content.

  39. #39
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    That then seems to interfere with the Next r further down the code (at the bottom of the below)

    For r = 1 To ws.Range("A" & Rows.Count).End(xlUp).Row
    If ws.Range(A & r) = "" Then GoTo ExitSub
    DumpRMA:
    If ws.Range(X & r).Value Like "*Email*" Then GoTo GetNextRow
    Rows(r).EntireRow.Delete Shift:=xlUp: GoTo DumpRMA
    GetNextRow: Next r


    wt.Range("A" & r).Value = ws.Range(A & r).Value

    Set BC = wt.Range("D" & r)
    If ws.Range(B & r).Value <> "" Then _
    BC.Value = ws.Range(B & r).Value: _
    BC.Interior.ColorIndex = -4142 _
    Else: BC.Value = ws.Range(BB & r).Value: _
    BC.Interior.ColorIndex = 6

    wt.Range("E" & r).Value = ws.Range(C & r).Value
    wt.Range("F" & r).Resize(1, 2).Value = ws.Range(D & r).Resize(1, 2).Value
    wt.Range("H" & r).Value = ws.Range(X & r).Value
    Next r
    ExitSub:

  40. #40
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    No - Like this:

    Please Login or Register  to view this content.
    * a better name would be ContinueProcessing:
    Last edited by xladept; 08-08-2017 at 06:39 PM.

  41. #41
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    oh sorry, got you know

    hmmmm, just tried it, but that also made excel hang and crash

  42. #42
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    I edited the last post - you do want to process those qualified records, right?

    So make the procedure name ContinueProcessing:

  43. #43
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    just tried to debug it and run line by line, and it seems to be stuck in a constant loop between these two lines

    If ws.Range(X & r).Value Like "*POO*" Then GoTo GetNextRow
    Rows(r).EntireRow.Delete Shift:=xlUp: GoTo DumpRMA

  44. #44
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Please Login or Register  to view this content.

  45. #45
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Quote Originally Posted by xladept View Post
    I edited the last post - you do want to process those qualified records, right?

    So make the procedure name ContinueProcessing:

    Sorry, what do you mean you edited the last post?

  46. #46
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Nevermind - look at #44

  47. #47
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    perfect, thank you

  48. #48
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Whew! You're welcome!

  49. #49
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    On this line,

    If ws.Range(X & r).Value Like "*Email*" Then GoTo ContinueProcessing

    Can you simply add an OR function after the "*Email*" to add another word?

  50. #50
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Please Login or Register  to view this content.
    * Thanks for the rep and the compliments!

  51. #51
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Not sure why, but this keeps crashing.

    I think its to do with the below section of code. If I run the code line by line its deletes all the rows with ou the word email in, then starts to move them to the Foretracker sheet, but it doesn't around 30 lines then loops contantly between this set of code

    If ws.Range(X & r).Value Like "*Email*" Then GoTo ContinueProcessing
    Rows(r).EntireRow.Delete Shift:=xlUp: GoTo DumpRMA


    Oddly, If I only have the word "Email" in the column, the code works ok, but the moment I introduce any other words (which it should filter out and delete that row) it just does as mentioned above and crashes excel.

    Any ideas?
    Last edited by rustyh; 08-09-2017 at 07:22 AM.

  52. #52
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Looks like it's overflowing - a rearrangement:

    Please Login or Register  to view this content.

  53. #53
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    That's working now per the code you posted, but the moment I introduce the second word value is crashes again

    If ws.Range(X & r).Value Like "*Email*" OR ws.Range(X & r).Value Like "*Icky-Poo*" Then GoTo ContinueProcessing

  54. #54
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    This ran for me

    Please Login or Register  to view this content.

  55. #55
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Booooooooooom.......works, not sure what the difference was with that new bit of code, but that's solved it a treat. Thank you


    You know how the code currently references a sheet called crossref for finding some additional data. Can VB find this if the sheet was in a different workbook instead (but in the same folder)?

  56. #56
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    As long as we know it's name we can do whatever we want (It's like magic)

    Please Login or Register  to view this content.

  57. #57
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Your not wrong, this VB is incredible

    Do you just insert this at the top of the code??

    Please Login or Register  to view this content.

  58. #58
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Not really - you've got to look for redundancies and the logical order and of course it should be pretty if possible

    Please Login or Register  to view this content.
    And - we need to test it

  59. #59
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    1 second of glory here, I spotted that you didn't have .xlsx wrapped in "" come on....its a step in the right learning direction for me!

    Anyway, its works up until this line --> Set wc = ActiveWorkbook.Sheets("Product List"): ws.Select: Q = Split(H, ",")
    at which point is highlights the ws.Select: section with the error of "Method 'Select' of object'_Worksheet' failed"

    It did however load up the external workbook ok

  60. #60
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Please Login or Register  to view this content.

  61. #61
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Your tooooooo good. Works a treat

    I guess I want to close that work book once done, I assume I can use Workbooks("XRefBook.xlsx").Close SaveChanges:=False but how do you work out where to put that cause of all the loops and subs

  62. #62
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    I already stuck it in down below i.e.

    Please Login or Register  to view this content.

  63. #63
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    arrrhhh, sorry, I hadn't copied that bit.

    Awesome, thanks mate

  64. #64
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    You're welcome!

  65. #65
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    On the crossref sheet, some of the crossref values are not being dragged across, like they are not being found. I have checked the part numbers are the same on both workbooks, but it doesn't seem to recognise some of them, any reason you could think of as to why?

  66. #66
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Ignore above, I figured out it was a data issue

  67. #67
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Thank you again for all the help on this
    Last edited by rustyh; 08-09-2017 at 07:11 PM.

  68. #68
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Blissfully ignoring!

  69. #69
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Hello Again,

    I seem to be having a issue with this, and I really can not figure out what I have done to cause this.

    The macro keeps throwing an error of "Method 'Range' of object'_Worksheet' failed, and it stops at line If ws.Range(A & r) = "" Then GoTo ExitSub

    Any idea?

  70. #70
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Check to see if r=0 - that may be the problem

  71. #71
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Got this sort now, I'd messed around to much!!

    I am trying to understand this bit of code, but its confused me a lot. What this is doing is take the part number in column A, then cross referencing it to column A in another sheet, and bringing back the values in column B and C of that sheet and pasting them in column B and C
    What I can not get my head around is where and how are the columns being selected in this. Essentially, all Im trying to do it to change its slight so that is takes the part number in column A, and this time cross references it to column B in the other sheet, and get the data in column A and C of that sheet and paste them in column B and C again

    Please Login or Register  to view this content.

  72. #72
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Essentially, all Im trying to do it to change its slight so that is takes the part number in column A, and this time cross references it to column B in the other sheet, and get the data in column A and C of that sheet and paste them in column B and C again
    So crossreference "A" from wc to "B" in wt then rewrite wc "B:C" from wt "A","C"??

    Please Login or Register  to view this content.
    Last edited by xladept; 08-24-2017 at 11:15 AM.

  73. #73
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Ok, IM even more lost now You have switch around r=2 and r=4 ?

    Tried is out and it doesn't seem to work.

  74. #74
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    The different sheets had different starting rows - do you have a different(!) situation?

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  75. #75
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Ok, attached is the layouts.

    I have altered the code to fetch the data from the forecast sheet I want. But this time column A of the forecast sheet is crossed to column B of the product list workbook, and I want to return column A and C instead.
    Attached Files Attached Files

  76. #76
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Well - again you'll need to change the book names

    Please Login or Register  to view this content.

  77. #77
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    sorry, where do I put these element?

    Below doesn't seem to work

    Please Login or Register  to view this content.

  78. #78
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    I'm confused - what, exactly. are we doing? I thought you had a different task

  79. #79
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    So the code you wrote before, I want the exact same task of is sorting through the values and deleting the ones I done want. That part worked ok after I changed some of it. But the section of code where it goes off to the product list, and cross references the part number, I just wanted to change that section to section from different columns

  80. #80
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    So originally you wrote this bit of code

    Please Login or Register  to view this content.
    Which works great, and I have used it. I am using it on a different sheet now as well, exactly the same scenario only I changed some of it slightly.
    But, this time, on the below section of code, I wanted it to cross reference column B (instead of A) of the part list, then return column A and C (Instead of Column B and C)

    Please Login or Register  to view this content.

  81. #81
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    It should work as long as the wp and wf are correctly defined - it worked here on your sample

  82. #82
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    What code are you referring to as worked? The one I just posted?

    The one I just posted is the original, which after its collated and sorted the data goes off to the Part List sheet/workbook, looks up the part number in column A of the part list, and then returns the data from column B and C of the part list against the match row in A column of the forecast.

    This time, the data in the new sheet I am setting up, the part number is actually the one in column B of the Part List, and I want to return the other part number in column A of the part list and the platform in column C. If you run the sheet I sent you earlier, it doesn't do this, Infact is doesn't seem to return any value.

    Note: I still want the functionality of it sorting through the data in the forecast sheet, and placing it in the sorted tab in a sorted order.

    If you run that spreadsheet I sent you earlier, that part of the VB doesn't fetch the data. I believe its because ori

  83. #83
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Well:

    wp was wc in the first version and wf was wt in the first version - I flipped them around to eliminate a third pass

  84. #84
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Im really lost mate, im not great with VB, apologies.

    So you posted

    Please Login or Register  to view this content.
    But don't I need to insert that in to this

    Please Login or Register  to view this content.
    If so, where?

  85. #85
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Let's put it in as a real subroutine:

    Please Login or Register  to view this content.

  86. #86
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    error on that as r As Long is repeated, but when I delete one the DIM goes black and errors

  87. #87
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Let me try it - please post a new sample.

  88. #88
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    Thanks, Please find attached
    Attached Files Attached Files

  89. #89
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    I think it ran like this but see whether that's where you wanted it - it's on forecast not on sorted

    Please Login or Register  to view this content.

  90. #90
    Registered User
    Join Date
    06-12-2014
    Posts
    61

    Re: Sorting Data

    That didn't work either, however, I think I have sorted it with the old code you made for me.

    Granted its probably not the most elegant way to do it, but I learnt quite a bit trying to figure it out. I realise that the code doesn't select each column from the product list table, it instead selects a cell then uses a resize function to select the adjacent cell, and I think that's what I originally didn't understand as I was trying to select A and C, so they were not adjacent.

    In the end, what I have done is copied specific section of code twice, and change the selection cell, but made it only paste the value in to 1 column rather than two.

    so I ended up with this

    Please Login or Register  to view this content.

    I did try and remove the resize part of this
    Please Login or Register  to view this content.
    but it kept throwing an error. So I basically changed this section
    Please Login or Register  to view this content.
    so it only returned in to one column.

    As I said, this is probably an ugly way of doing it, so would be keen to know how you would tidy this up

    Full code below

    Please Login or Register  to view this content.

  91. #91
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Sorting Data

    Here is code that should run neatly:

    Please Login or Register  to view this content.
    * The .Item(PN) is just the row number where that key was scanned

+ 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: 1
    Last Post: 12-16-2015, 01:04 PM
  2. Replies: 0
    Last Post: 02-24-2014, 11:27 AM
  3. Sorting all data based on data in single column (DATES)
    By subbby in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-16-2013, 08:19 AM
  4. [SOLVED] Data Analysis: Comparing 3 columns, sorting, removing unique values, display data
    By kmills2626 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-14-2013, 07:27 AM
  5. Sorting 2 data ranges by comparing one column in each and sorting to match
    By MDKsmiffy in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-17-2013, 03:30 PM
  6. Replies: 3
    Last Post: 12-20-2012, 06:16 AM
  7. Sorting, finding dulicates, moving one data element up, deleting original data
    By rickwtx in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 01-13-2011, 07:32 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