Need some help with extracting unique values(tricky..).

alexanderd52

New Member
Joined
Mar 1, 2009
Messages
4
Hello,

Before I start I want to say that English is not my first language, I am really sorry and i hope you understand... Also, after I’ve spent 3 hours writing formulas in excel my head isn’t really working that great, so my explanation of what I need might be kinda bad.

Anyway, I have fixed amount of columns (6 in example: can be seen at sheet called "llist1", more in real example:"real example of list1") and rows (8 in example, 62 in “real example").
These 6 "analyzed" columns consist 3 type of info, basically there were 3 columns, which were "cut" to 6. In my example those types of info are called "name1"(columns A and F), "name2"(B and G) and "a or b"(C and H). Also there are rows, which should not be “analyzed”.

First, according to example sheet called "list1", i need to extract unique values from some "fixed" rows of columns A and F, more detailed: a2:a4 a6:a8 f2:f4 f6:f8. Probably, a named list should be created. Also it would be great, if these names will be extracted in alphabetical order. This is the first problem.

Then there goes second, the big one, problem: I need to extract unique values from !"rows of fixed rows"! of columns B and G "for" extracted unique values from columns A and F.
It is really easier to understand if you look at the analyzed information structure at the example sheet and what I want have in the end at "ideal" or "wanted" sheets.
By saying "rows of rows" I mean something like this: cell B2 contains this:
1st "row": abc-301
2nd "row": abc-302
3rd "row: abc-303
All this rows, thanks god, always contain 7 signs. I suppose a second named list is needed here, i e: b2:b4 b6:b8 g2:g4 g6:g8

After that I need to count A's or B's, according to rows, already done that myself using asterisks.

Thank you for help.

PS: how can i attach an excel file? :( checkick the faq info, the spreadsheet will appear in a couple of minutes...
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hello and welcome to MrExcel.

You can't attach an Excel file but you can post a picture of your sheet using Excel Jeanie. I think that should help in trying to understand your problem.
 
Upvote 0
This is an example:
Excel Workbook
ABCDEFGH
1name1name2a or b**name1name2a or b
2pandaabc-301abc-302abc-303a**pandaabc-301abc-302abc-303a
3zebraabc-301b**zebraabc-301b
4pandacab-301cab-302cab-303a**zebracab-301cab-302cab-303a
5not empty row here, which should not be used.
6pandaabc-301abc-302abc-303a**zebraabc-301abc-302abc-303a
7pandaabc-123abc-124abc-125b**zebraabc-508b
8zebraabc-302b**zebrabre-101b
list1


This is what i need, according to information from the example:
Excel Workbook
ACDE
1Name1*Name2**AB
2pandaabc-12301
3*abc-12401
4*abc-12501
5*abc-30130
6*abc-30230
7*abc-30330
8*cab-30110
9*cab-30210
10*cab-30310
11zebraabc-30112
12*abc-30211
13*abc-30310
14*abc-50801
15*bre-10101
16*cab-30110
17*cab-30210
18*cab-30310
19**188
ideal result
 
Upvote 0
Sorry for flooding and for the amount of formulas in previous sheet, will try to delete that part... no need to read those, its the done "counting a's and b's" part.

This is the real structure of the document i need to extract from(3 of 6 "blocks", a5:k12 is one, then there are two none-analyzed rows, then next block etc):
Excel Workbook
ABCDEFGHIJK
1info
2info*info
3info
4infoname1name2a or binfo*infoname1name2a or binfo
5info*****info****
6info*****info****
7info*****info****
8info*****info****
9info*****info****
10info*****info****
11info*****info****
12info*****info****
13info
14infoname1name2a or binfo*infoname1name2a or binfo
15info*****info****
16infofirst unique nameabc-101binfo*info3rd nameqwe-101rty-101ainfo
17infofirst unique nameabc-102binfo*info3rd namepio-101ainfo
18infofirst unique nameabc-103binfo*info3rd nametyu-101ainfo
19infosecond nameabc-104binfo*info3rd nameasd-301binfo
20infosecond nameabc-105binfo*info3rd namebac-302binfo
21info*****info****
22info*****info****
23info
24infoname1name2a or binfo*infoname1name2a or binfo
25info*****info****
26infofirst nameABC-101binfo*infosecond namezxc-122ainfo
27infofirst nameABC-102binfo*info3rd nameqwe-101rty-101ainfo
28infofirst nameABC-103binfo*infofirst nameqwe-101rty-101ainfo
29infofirst nameABC-104binfo*infofirst nameabc-101ainfo
30infofirst nameABC-105binfo*infofirst nameqwe-123binfo
31info*****infofirst nameqwe-101rty-101binfo
32info*****infofirst nameabc-103binfo
real example of "list1"
 
Upvote 0
Hi Alexander and welcome the the board!

I am Russian too. Could you explain me you task more clearly by using of private message (PM). For the case I'll send you my e-mail. After clearing we could post here the details of issue or result of it solving.

Regards,
Vladimir
 
Upvote 0
Alexander, I have sent you PM with my e-mail address.
Your task of unique amount calculation could be solved by the aid of macro.
Could you e-mail me workbook with a part of input data?
Vladimir
 
Upvote 0
The current state of the task after conversation with Alexander as follows:

1. Input data of "Data" Sheets(1) looks like this:
Excel Workbook
ABCDEFGHIJK
1info
2infoinfo
3info
4infoname1name2a or binfoinfoname1name2a or binfo
5infoinfo
6infoinfo
7infoinfo
8infoinfo
9infoinfo
10infoinfo
11infoinfo
12infoinfo
13info
14infoname1name2a or binfoinfoname1name2a or binfo
15infoinfo
16infofirst unique nameabc-101binfoinfo3rd nameqwe-101rty-101ainfo
17infofirst unique nameabc-102binfoinfo3rd namepio-101ainfo
18infofirst unique nameabc-103binfoinfo3rd nametyu-101ainfo
19infosecond nameabc-104binfoinfo3rd nameasd-301binfo
20infosecond nameabc-105binfoinfo3rd namebac-302binfo
21infoinfo
22infoinfo
23info
24infoname1name2a or binfoinfoname1name2a or binfo
25infoinfo
26infofirst nameABC-101binfoinfosecond namezxc-122ainfo
27infofirst nameABC-102binfoinfo3rd nameqwe-101rty-101ainfo
28infofirst nameABC-103binfoinfofirst nameqwe-101rty-101ainfo
29infofirst nameABC-104binfoinfofirst nameabc-101ainfo
30infofirst nameABC-105binfoinfofirst nameqwe-123binfo
31infoinfofirst nameqwe-101rty-101binfo
32infoinfofirst nameabc-103binfo
Data


2. Expected result of "Result" Sheets(2) are the unique concatenated values of each input rows given from columns B:C and H:I of Sheets(1), excluding the title and empty cells:
Excel Workbook
ABCD
13rd nameasd-301
2bac-302
3pio-101
4qwe-101
5rty-101
6tyu-101
7first nameABC-101
8ABC-102
9ABC-103
10ABC-104
11ABC-105
12qwe-101
13qwe-123
14rty-101
15first unique nameabc-101
16abc-102
17abc-103
18second nameabc-104
19abc-105
20zxc-122
Result


3. The code for providing expected result:
Rich (BB code):
<font face=Courier New>
' ZVI:2009-03-02 http://www.mrexcel.com/forum/showthread.php?t=374600
Sub Start()
  Dim Arr, Tmp, Dic, s As String, i As Long, x, cs
  Const Title = "name1"         ' <-- Title to be skipped
  Const SheetFrom = 1           ' <-- Sheet with input data, string or numeric
  Const SheetTo = 2             ' <-- Sheet with output data, string or numeric
  Const ColumnsFrom = "B:C,H:I" ' <-- List of input colums (pared)
  '  Clear destination
  With Sheets(SheetTo)
    Application.Intersect(.UsedRange, .Columns("A:B")).ClearContents
  End With
  ' Build unique from B:C & H:I
  With CreateObject("Scripting.Dictionary") 'Dic
    .CompareMode = vbTextCompare
    For Each cs In Split(ColumnsFrom, ",")
      Arr = Application.Intersect(Sheets(SheetFrom).UsedRange, Sheets(SheetFrom).Columns(Trim(cs))).Value
      For i = 1 To UBound(Arr)
        If Len(Arr(i, 1)) > 1 And Arr(i, 1) <> Title Then
          For Each x In Split(Arr(i, 2), vbLf)
            If Len(x) > 0 Then
              s = Arr(i, 1) & vbLf & x
              If Not .Exists(s) Then .Add s, 0
            End If
          Next
        End If
      Next
    Next
    ' Copy result to Arr
    On Error GoTo exit_:
    Tmp = .Keys
    ReDim Arr(1 To .Count, 1 To 2)
    For i = 1 To .Count
      x = Split(Tmp(i - 1), vbLf)
      Arr(i, 1) = x(0)
      Arr(i, 2) = x(1)
    Next
  End With
  ' Copy result to Sheets(2)
  With Application
    ' Freeze on
    .EnableEvents = False
    .ScreenUpdating = False
    ' Write result to destination columns
    With Sheets(SheetTo).Range("A1").Resize(UBound(Arr), 2)
      ' Copy result as values
      .Value = Arr
      ' Sort resulting columns
      .Sort Key1:=.Cells(1, 1), Order1:=xlAscending, _
            Key2:=.Cells(1, 2), Order2:=xlAscending, Header:=xlNo
      ' Del equal items in Columns(1)
      Arr = .Columns(1)
      s = Arr(1, 1)
      For i = 2 To UBound(Arr)
        If Arr(i, 1) = s Then Arr(i, 1) = "" Else s = Arr(i, 1)
      Next
      .Columns(1).Value = Arr
    End With
    ' Freeze off
    .EnableEvents = True
    .ScreenUpdating = True
  End With
  Exit Sub
exit_:
  MsgBox Err.Number & vbLf & Err.Description, vbCritical, "Error!"
End Sub
</FONT>

Vladimir
 
Last edited:
Upvote 0
Version with calculation of occurrences amount in 3d resulting column:
Excel Workbook
ABCD
13rd nameasd-3011
2bac-3021
3pio-1011
4qwe-1012
5rty-1012
6tyu-1011
7first nameABC-1012
8ABC-1021
9ABC-1032
10ABC-1041
11ABC-1051
12qwe-1012
13qwe-1231
14rty-1012
15first unique nameabc-1011
16abc-1021
17abc-1031
18second nameabc-1041
19abc-1051
20zxc-1221
Result


Revised code:
Rich (BB code):
<font face=Courier New>
Sub Start()
  Dim Arr, Tmp, s As String, i As Long, x, cs
  Const Title = "name1"         ' <-- Title to be skipped
  Const SheetFrom = 1           ' <-- Sheet with input data, string of numeric
  Const SheetTo = 2             ' <-- Sheet with output data, string of numeric
  Const ColumnsFrom = "B:C,H:I" ' <-- List of input colums (pared)
  '  Clear destination
  With Sheets(SheetTo)
    Application.Intersect(.UsedRange, .Columns("A:C")).ClearContents
  End With
  ' Build unique from B:C & H:I
  With CreateObject("Scripting.Dictionary")
    .CompareMode = vbTextCompare
    For Each cs In Split(ColumnsFrom, ",")
      Arr = Application.Intersect(Sheets(SheetFrom).UsedRange, Sheets(SheetFrom).Columns(Trim(cs))).Value
      For i = 1 To UBound(Arr)
        If Len(Arr(i, 1)) > 0 And Arr(i, 1) <> Title Then
          For Each x In Split(Arr(i, 2), vbLf)
            If Len(x) > 0 Then
              s = Arr(i, 1) & vbLf & x
              If Not .Exists(s) Then .Add s, 1 Else .Item(s) = .Item(s) + 1
            End If
          Next
        End If
      Next
    Next
    ' Copy result to Arr
    On Error GoTo exit_:
    Tmp = .Keys
    ReDim Arr(1 To .Count, 1 To 3)
    For i = 1 To .Count
      x = Split(Tmp(i - 1), vbLf)
      Arr(i, 1) = x(0)
      Arr(i, 2) = x(1)
      Arr(i, 3) = .Item(Tmp(i - 1))
    Next
  End With
  ' Copy result to Sheets(2)
  With Application
    ' Freeze on
    .EnableEvents = False
    .ScreenUpdating = False
    ' Write result to destination columns
    With Sheets(SheetTo).Range("A1").Resize(UBound(Arr), 3)
      ' Copy result as values
      .Value = Arr
      ' Sort resulting columns
      .Sort Key1:=.Cells(1, 1), Order1:=xlAscending, _
            Key2:=.Cells(1, 2), Order2:=xlAscending, Header:=xlNo
      ' Del equal items in Columns(1)
      Arr = .Columns(1)
      s = Arr(1, 1)
      For i = 2 To UBound(Arr)
        If Arr(i, 1) = s Then Arr(i, 1) = "" Else s = Arr(i, 1)
      Next
      .Columns(1).Value = Arr
    End With
    ' Freeze off
    .EnableEvents = True
    .ScreenUpdating = True
  End With
  Exit Sub
exit_:
  MsgBox Err.Number & vbLf & Err.Description, vbCritical, "Error!"
End Sub
</FONT>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,086
Messages
6,128,734
Members
449,466
Latest member
Peter Juhnke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top