I am using Microsoft Excel for Mac (Version 16.81 from Microsoft 365)
I am analysing a number of questionnaires which contain information in Row1 that I need to extricate. Here are the steps:
1. Row 1 has some data followed by (from Column H) text field counting Roles and Organisations (R&O) which are comma separated.
(e.g. Clinical nurse, CAHS)
2. The R&O information starts from Column H and probably has a limit of 30 entries.
3. Each R&O entry is repeated a number of times, dependent upon the questionnaire.
4. In the example provided (see attached spreadsheet) there are six unique R&Os. I have highlighted the first one ("Senior Community Engagement Officer, Department of Communities") and indicated when it repeated.
Task:
Task 1: Find the number of unique R&Os (in this case six)
Task 2: Store data onto a second sheet (named R&O in the attached sheet). This sheet has been manually developed for illustration of how it should look.
Task 3: Data to be in two columns headed Role and Organisation
I have provided my attempt at VBA which does not appear to be working. Again, this is my first VBA attempt.
Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
MS-Off Ver
MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
Posts
90,181
Re: Searching for duplicate txt in a Row
Administrative Note:
Welcome to the forum.
Is your forum profile showing the Excel PRODUCT that you need this to work for?
Members will tailor the solutions they offer to the Office PRODUCT (Excel, NOT Windows) that you have. Please check that your forum profile is up-to-date in this respect. If you aren't sure, in Excel go to File | Account and report what it says below the MS logo at the top of that page. If your product is for Mac, please also state this.
The three most recent Excel products are Excel 2019, Excel 2021 and MS365 - if you are using MS365, please give this name along with the version number in your profile (e.g. MS365 Version 2306). This is in the About Excel section further down the Account page.
Thanks.
Ali Enthusiastic self-taught user of MS Excel who's always learning! Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy. You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.
NB: as a Moderator, I never accept friendship requests. Forum Rules (updated August 2023): please read them here.
In the first worksheet ("Data") Row 1 , from Column H onwards contains text fields. These are Roles and Organisations (R&O) separated by a comma (CSV).
For example H1. shows, "Senior Community Engagement Officer, Department of Communities" the first part is the Role ("Senior Community Engagement Officer,") and the second part is the Organisation ("Department of Communities").
Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
MS-Off Ver
MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
Posts
90,181
Re: Searching for duplicate txt in a Row
See the improved version just above.
Glad to have helped.
If that takes care of your original question, please choose Thread Tools from the menu link above and mark this thread as SOLVED. You can also access the SOLVED tag by editing the opening post and choosing SOLVED from the drop-down to the left of the title box.
Also, if you have not already done so, remember that you can reward anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of each of those who offered help.
Note that for both Ali's formula and my macro code these are identified as two different entries:
Deputy Principal, La Grange Remote community school
Deputy Principal, La Grange Remote School
Try this code.
Please note that some cells have similar content, differing by only (or with excess, or missing) a few characters, which will be treated as separate cases.
Example:
"La Grange Remote community school"
vs
"La Grange Remote school"
PHP Code:
Option Explicit
Sub findRO()
Dim lc&, i&, k&, rng, res(1 To 1000, 1 To 2), sp
Dim dic As Object
Set dic = CreateObject("scripting.dictionary")
With Sheets("Data")
lc = .Cells(1, Columns.Count).End(xlToLeft).Column 'Last used column
rng = .Range(.Cells(1, "H"), .Cells(1, lc)).Value 'value of range from H1 to last cell in row 1
End With
For i = 1 To UBound(rng, 2) ' loop thru rng
If InStr(1, rng(1, i), "?") = 0 And rng(1, i) <> "" Then 'cells contain "?" will be excluded, not counted.
If Not dic.exists(UCase(rng(1, i))) Then
sp = Split(rng(1, i), ",")
dic.Add UCase(rng(1, i)), ""
k = k + 1: res(k, 1) = sp(0): res(k, 2) = sp(1)
End If
End If
Next
Sheets("R&O").Activate
Range("A2:B10000").ClearContents
If k > 0 Then Range("A2").Resize(k, 2).Value = res
End Sub
Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
MS-Off Ver
MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
Posts
90,181
Re: Searching for duplicate txt in a Row
If you have not already done so, remember that you can reward anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of each of those who offered help.
Bookmarks