Hi
I have a workbook, where a userform is used to store data for each room.
In a large building it can be several hundreds of rooms - so I want to be able to search for a particular room.
The roomnumber is unique on each floor - that is the combination floor/ roomnumber is unique.
I have a sub that searches roomnumber and floor but it returns the last row with search floor and last row with search roomnumber and that is not nessesarily the same row.
I use this code:
I only want to look for the floor, when the roomnumber match.
Can you help me on that?
Thankyou regards
Annette
I have a workbook, where a userform is used to store data for each room.
In a large building it can be several hundreds of rooms - so I want to be able to search for a particular room.
The roomnumber is unique on each floor - that is the combination floor/ roomnumber is unique.
I have a sub that searches roomnumber and floor but it returns the last row with search floor and last row with search roomnumber and that is not nessesarily the same row.
I use this code:
Code:
Private Sub cmdSøgRum_Click()
Dim lIsInRow, lIsInRow2 As Variant ' Long
Dim rngRumnrListe, rngEtageListe As Range
Dim sRumEtage As String
Dim sSøgString As String
Dim søgArray As Variant
Dim Rum As String, Etage As String
Dim i As Long, j As Long
'Promt for room to find
sRumEtage = "Which room and floor to search?" & vbNewLine
sRumEtage = sRumEtage & "Seperate roomnumber and floor by "";"""
sSøgString = InputBox(sRumEtage, Title:="RoomSearch")
søgArray = Split(sSøgString, ";")
Rum = søgArray(0) ' room
Etage = søgArray(1) ' floor
MsgBox ("room and floor is: " & Rum & " " & "" & Etage)
With ActiveSheet
Set rngRumnrListe = Range(.Range("B2"), .Cells(.Rows.Count, "B").End(xlUp))
Set rngEtageListe = Range(.Range("A2"), .Cells(.Rows.Count, "A").End(xlUp))
' check room number
If Not IsError(Application.Match(Rum, rngRumnrListe, 0)) Then
' MsgBox "Rumnummer er brugt", vbInformation, vbNullString ' Besked om at nummeret er brugt
lIsInRow = Cells.Find(what:=Rum, after:=[B1], Searchorder:=xlByRows, _
Searchdirection:=xlPrevious).Row
MsgBox ("Room is in row number " & lIsInRow)
' check floor
If Not IsError(Application.Match(Etage, rngEtageListe, 0)) Then
'MsgBox "Floor is used", vbInformation, vbNullString
lIsInRow2 = Cells.Find(what:=Etage, after:=[B1], Searchorder:=xlByRows, _
Searchdirection:=xlPrevious).Row
MsgBox ("Floor is in rownumber " & lIsInRow2)
lCurrentRow = lIsInRow2
VisAktuelRække ' sub to populate the userform with data for the actual room
End If
End If
End With
End Sub
I only want to look for the floor, when the roomnumber match.
Can you help me on that?
Thankyou regards
Annette