Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Sort words copied from pdf for excel output to descending numbered order

0

I would love to be able to copy a selected text and have words between semi colon sorted in decending order in an excel column.

Example data set below ,

Nonmetallic Mineral Products; Furniture & Related Products; Plastics &
Rubber Products; Primary Metals; Machinery; Wood Products; Fabricated Metal
Products; Computer & Electronic Products;
 

would sort to 

Nonmetallic Mineral Products;         7

Furniture & Related Products;         6

Plastics & Rubber Products;            5

Primary Metals; Machinery;             4

Wood Products;                               3

Fabricated MetalProducts;              2

Computer & Electronic Products;    1

Data ranges from 1 - 18 (see table below) and is random depending on sample taken

Thank you so much , sorry if thats not clear .

currently using =IFERROR(VLOOKUP(B3,F:G,2,FALSE),0)

would like to cut out having to edit the original word copy from pdf.

(Please see attached excel doc for current setup)

ultimate goal is to have the following column "A" that doesnt change with only relevant data correctly inserted into column "B" after a pdf/word scan

Apparel, Leather & Allied Products; Chemical Products; Computer & Electronic Products; Electrical Equipment, Appliances & Components; Fabricated Metal Products; Food, Beverage & Tobacco Products; Furniture & Related Products; Machinery; Miscellaneous Manufacturing; Nonmetallic Mineral Products; Paper Products; Petroleum & Coal Products; Plastics & Rubber Products; Primary Metals; Printing & Related Support Activities; Textile Mills; Transportation Equipment; Wood Products;
Answer
Discuss

Discussion

Hello Alaya,
What's your question?
Variatus (rep: 4889) Jul 11, '21 at 8:44 pm
Im sorry, let me try be more clear.

to take this Data:

Nonmetallic Mineral Products; Furniture & Related Products; Plastics &
Rubber Products; Primary Metals; Machinery; Wood Products; Fabricated Metal Products; Computer & Electronic Products;


and automatically sort into two columns 

column A = name  ie (Nonmetallic Mineral Products;)
column B = decending number value (18-1)

so for the above data set it would output 

Nonmetallic Mineral Products;         8
Furniture & Related Products;          7
Plastics & Rubber Products;            6
Primary Metals;                                5
Machinery;                                        4
Wood Products;                                3
Fabricated Metal Products;              2
Computer & Electronic Products;     1
Alaya108 (rep: 4) Jul 12, '21 at 4:34 pm
Add to Discussion

Answers

0
Selected Answer

Hi Alaya and welcome to the Forum

In the attached file I've used VBA to solve your problem (hopefully).

If you paste a string like:

   Nonmetallic Mineral Products; Furniture & Related Products; Plastics & Rubber Products; Primary Metals; Machinery; Wood Products; Fabricated Metal Products; Computer & Electronic Products;

into (merged) cell F2 then click the green button below it, the code in Module 1 (shown below) will run and add rank numbers in the column to the right of your "fixed" list in B3:B20. If there are 7 tiems, it'll be 7 to 1 but if there are 12, 12 to 1 etc. It will also put today's date in cell C1 (I assume the updates are weekly or monthly)

Furthermore if it doesn't match an item, a message box will tell you. (Try this by running the macro then in F2 make Wood Products read Wood2Products say then run the macro again.

I've added comments (in maroon, after the ' ) to give you clues on how this code works:

Option Base 1

Sub WordsToRank()

Dim NewRanks As Variant, m as Long, n as Long
Dim Found as Boolean, NotFound as String
Range("C1").Value = Date  ' add date
Range("C3:C20").Value = "" 'clear ranks

NewRanks = Split(Range("F2"), ";") ' extract the text between ; delimiters into an array

If Right(Range("F2").Value, 1) = ";" Then ReDim Preserve NewRanks(UBound(NewRanks) - 1) ' remove last array element perhaps
For m = LBound(NewRanks) To UBound(NewRanks) ' loop through data array then...

    Found = False
    For n = 3 To 20 'loop through fixed category rows
        If Trim(NewRanks(m)) = Trim(Range("B" & n).Value) Then 'try to match each element with items in fixed list
            Range("C" & n).Value = UBound(NewRanks) - m + 1 'set the rank in matched cell
            Found = True 'mark as matched
        End If
    Next n
    If Found = False Then NotFound = NotFound & vbLf & NewRanks(m) 'collect any matches not found
Next m

If NotFound <> "" Then 'say if the outcome wasn't wholly successful
    r = MsgBox("Done but please check spelling of fixed Category c.f. un-matched ISM data:" _
    & vbLf & NotFound, vbOKOnly, "Didn't match some ISM data")
    Else
    MsgBox "Done!" 'or say it was
End If

End Sub
Hope this does what you want.
Discuss

Discussion

Thank you !  This is amazing and inspiring ! It works perfectly and will save an immense amount of time, I truly appreciate.
Alaya108 (rep: 4) Jul 13, '21 at 2:16 am
Alaya. That's a lovely reaction and thanks for selecting my answer. If you subscribe to TeachExcel and follow Don's video tutorials, you'll learn how to use much more of Excel's power
John_Ru (rep: 6152) Jul 13, '21 at 2:48 am
Thank you , I will do.
Alaya108 (rep: 4) Jul 17, '21 at 1:14 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login