Return the next unique value in a range

tallinex

New Member
Joined
Sep 8, 2017
Messages
1
qgppKlo.jpg


Hello All,
I am wanting to have a formula in cell A21, A22, A23 and A24 that will look for the string value in the cell above within the 4 week calendar in the top section (range A2:G17) and return the next value (hotel name) to basically build up a list of unique values.
For the first cell in the list i have set it to look for the first non-blank cell in the first hotel row (=INDEX(A4:G4,MATCH(TRUE,INDEX((A4:G4<>0),0),0)))

Any help is apriciated
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Welcome to the MrExcel board!

For the future, note that you will attract more potential helpers (& faster help) if you post your sample data in a form that can be copied from your post to a worksheet for testing. My signature block below has a link with options.

Somebody will quite likely come up with a formula solution for you, but here is a user-defined function that you may wish to consider. To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown** in the screen shot below and copy down.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

** Note that the function has 3 arguments.
- A range that includes all the hotels names. The first row of the range must be the first row containing hotel names. The 'hotel rows' must be uniformly spaced in the range.
- The 'RowGap' being that uniform spacing of the hotel rows within the above range.
- Which item in the list to be returned. These values will be 1, 2, 3 etc as the formula is copied down.

Code:
Function NextHotel(rng As Range, RowGap As Long, ItmNum As Long) As String
  Dim d As Object
  Dim a As Variant
  Dim rw As Long, col As Long

  Set d = CreateObject("Scripting.Dictionary")
  d.CompareMode = 1
  a = rng.Value
  For rw = 1 To UBound(a) Step RowGap
    For col = 1 To UBound(a, 2)
      If Len(a(rw, col)) > 0 Then
        d(a(rw, col)) = 1
      End If
    Next col
  Next rw
  If ItmNum <= d.Count Then NextHotel = d.keys()(ItmNum - 1)
End Function


Excel 2016 (Windows) 32 bit
ABCDEFG
230/07/201731/07/20171/08/20172/08/20173/08/20174/08/20175/08/2017
3
4Hilton ParisHilton ParisHilton ParisHilton ParisHilton ParisMecure Frankfurt
5
66/08/20177/08/20178/08/20179/08/201710/08/201711/08/201712/08/2017
7
8Mecure FrankfurtMecure FrankfurtMecure FrankfurtHilton LondonHilton LondonHilton LondonHilton London
9
1013/08/201714/08/201715/08/201716/08/201717/08/201718/08/201719/08/2017
11
12Hilton LondonHilton LondonHilton LondonHilton LondonHilton LondonHilton LondonHilton London
13
1420/08/201721/08/201722/08/201723/08/201724/08/201725/08/201726/08/2017
15
16
17
18
19Hotels
20Hilton Paris
21Mecure Frankfurt
22Hilton London
23
24
Hotel List
Cell Formulas
RangeFormula
A20=NextHotel(A$4:G$16,4,ROWS(A$20:A20))
 
Last edited:
Upvote 0
A picture is not Excel readable, forcing a would-be helper to retype everything in order to experiment!...

In A20 control+shift+enter, not just enter, and copy down:

=IFERROR(INDEX($A$4:$G$4,SMALL(IF(FREQUENCY(IF(1-($A$4:$G$4=""),MATCH($A$4:$G$4,$A$4:$G$4,0)),COLUMN($A$4:$G$4)-COLUMN($A$4)+1),TRANSPOSE(COLUMN($A$4:$G$4)-COLUMN($A$4)+1)),ROWS($A$20:A20))),"")
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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