Consulting

Results 1 to 6 of 6

Thread: Solved: Search Range of numbers and return missing

  1. #1

    Solved: Search Range of numbers and return missing

    Dears,

    Could you please help me (with excel function or macro) to search occupied room numbers in columns (B & D) and return to me the free numbers in the range of (512 to 536)
    Attached Files Attached Files

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Return to you how?

  3. #3
    Sorry, I mean show me the missing numbers in Different column called Output for example in different cells

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    [VBA]
    Private Sub CommandButton1_Click()
    'Early Binding method requires Reference: MicroSoft Scripting Runtime, scrrun.dll
    'Dictionary Help File: http://www.microsoft.com/download/en...s.aspx?id=2764
    'Dictionary Examples and Discussion:
    'http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/A_3391-Using-the-Dictionary-Class-in-VBA.html

    Dim rnRange As Range, i As Integer, cell As Range
    'Dim d As Object 'Late Binding method
    Dim d As Dictionary 'Early Binding method
    Set d = New Dictionary 'Early Binding Method

    Set rnRange = Union(Range("B2", Range("B" & Rows.Count).End(xlUp)), _
    Range("D2", Range("D" & Rows.Count).End(xlUp)))
    For i = 512 To 536
    d.Add i, i
    Next i

    For Each cell In rnRange
    If d.Exists(cell.Value) Then d.Remove (cell.Value)
    Next cell

    If Not d.Count = 0 Then Range("E2").Resize(d.Count).Value = WorksheetFunction.Transpose(d.Keys())

    Set d = Nothing
    End Sub[/VBA]

  5. #5
    Dear Expert,
    Thanks for your support but I couldn't understand your code, hereby I received this message error (Compile error: User-defined type not defined)

    and Highlighting below script
    d as Dictionary

    Sorry, I'm confuded and don't know how to fix it out!

  6. #6
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    You have to set the reference in Tools > References as the first comment explained. Comments are your friend.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •