+ Reply to Thread
Results 1 to 11 of 11

Search 2 criteria "Reservation panel"

  1. #1
    Registered User
    Join Date
    03-30-2017
    Location
    Brazil
    MS-Off Ver
    2019
    Posts
    54

    Post Search 2 criteria "Reservation panel"

    Hi everyone!

    I am creating a spreadsheet template where I need to schedule some machines by date as shown in the example below.
    1.PNG

    In a form, I need to select the date and check which machines are available and which are reserved for the selected date.

    That is, I will select a date and cad Textbox should show the status "Reserved" or "Available".

    2.PNG

    I tried to do this using a For Next Loop, but I was only able to do it for the first Textbox.

    Could someone help me in this case?

    Thanks in advance.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !


    According to your attachment a VBA demonstration as a beginner starter :

    PHP Code: 
    Private Sub CommandButton2_Click()
            
    Dim R&, Rf As RangeM%(1 To 4)
        If 
    Not txtDate Like "*/*/*" Then
            
    For 1 To 4:  Controls("txtM" R) = "":  Next
            
    If txtDate "" Then Beep
        
    Else
            
    With Planilha1.[A1].CurrentRegion.Columns(1)
                   
    Set Rf = .Find(CDate(txtDate), , , 1)
                If 
    Not Rf Is Nothing Then
                           R 
    Rf.Row
                    
    Do
                       
    M(Split(Rf(12).Text)(1)) = 1
                           Set Rf 
    = .FindNext(Rf)
                    
    Loop Until Rf.Row R
                           Set Rf 
    Nothing
                End 
    If
            
    End With
                
    For 1 To 4:  Controls("txtM" R) = Array("Available""Reserved")(M(R)):  Next
        End 
    If
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 10-16-2021 at 01:44 PM.

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Re: Search 2 criteria "Reservation panel"


    And button #2 is usesles just with this :

    PHP Code: 
    Private Sub CommandButton1_Click()
        
    txtDate GetCalendário
        txtDate_AfterUpdate
    End Sub

    Private Sub txtDate_AfterUpdate()
            
    Dim R&, Rf As RangeM%(1 To 4)
        If 
    Not txtDate Like "*/*/*" Then
            
    For 1 To 4:  Controls("txtM" R) = "":  Next
            
    If txtDate "" Then Beep
        
    Else
            
    With Planilha1.[A1].CurrentRegion.Columns(1)
                   
    Set Rf = .Find(CDate(txtDate), , , 1)
                If 
    Not Rf Is Nothing Then
                           R 
    Rf.Row
                    
    Do
                       
    M(Split(Rf(12).Text)(1)) = 1
                           Set Rf 
    = .FindNext(Rf)
                    
    Loop Until Rf.Row R
                           Set Rf 
    Nothing
                End 
    If
            
    End With
                
    For 1 To 4:  Controls("txtM" R) = Array("Available""Reserved")(M(R)):  Next
        End 
    If
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 10-16-2021 at 01:42 PM.

  4. #4
    Registered User
    Join Date
    03-30-2017
    Location
    Brazil
    MS-Off Ver
    2019
    Posts
    54

    Re: Search 2 criteria "Reservation panel"

    That was really perfect Marc
    This code contains some things I've never seen with VBA.
    Thanks for your help

  5. #5
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Search 2 criteria "Reservation panel"

    Or Slightly easier and faster.

    Please Login or Register  to view this content.
    Messages have been translated from Dutch to English by means of google translate.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Search 2 criteria "Reservation panel"


    Hi Vraag !

    I need some light about your logic : If ar(j, 2) = "Machine " & jj Or Controls("txtM" & jj) = "Reserverd" Then Controls("txtM" & jj) = "Reserverd"

    It seems the Or part is useless …

  7. #7
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Search 2 criteria "Reservation panel"

    @Marc L, that's right. The code used to be different and this part has remained.

  8. #8
    Registered User
    Join Date
    03-30-2017
    Location
    Brazil
    MS-Off Ver
    2019
    Posts
    54

    Post Re: Search 2 criteria "Reservation panel"

    Marc,
    I don't want to abuse your courtesy, but another question has arisen.
    If I have an extra time field as shown below.

    1.PNG
    2.PNG

    What would this code look like with this additional criteria?
    Attached Files Attached Files
    Last edited by hpernaf; 10-16-2021 at 08:10 PM.

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Re: Search 2 criteria "Reservation panel"


    So with the time as criteria :

    PHP Code: 
    Private Sub CommandButton2_Click()
          Const 
    "txtM"
            
    Dim D As DateRf As RangeR&, M%(1 To 4)
        If 
    IsDate(txtDate) And IsDate(txtTimeThen
            With Planilha1
    .[A1].CurrentRegion.Columns(1)
                    
    CDate(txtDate)
                    If 
    Len(txtDate) < 10 Then txtDate D
                    Set Rf 
    = .Find(D, , , 1)
                    
    CDate(txtTime)
                    If 
    Len(txtTime) < 5 Then txtTime Left(D5)
                If 
    Not Rf Is Nothing Then
                       R 
    Rf.Row
                
    Do
                        If 
    Rf(12).Value D Then M(Split(Rf(13).Text)(1)) = 1
                       Set Rf 
    = .FindNext(Rf)
                
    Loop Until Rf.Row R
                       Set Rf 
    Nothing
                End 
    If
            
    End With
                
    For 1 To 4:  Controls(R) = Array("Available""Reserved")(M(R)):  Next
        
    Else
            For 
    1 To 4:  Controls(R) = "":  Next
            
    If txtDate "" Or txtTime "" Then Beep
        End 
    If
    End Sub 
    Last edited by Marc L; 10-16-2021 at 09:29 PM. Reason: optimization …

  10. #10
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Search 2 criteria "Reservation panel"

    You will also need to specify an end time or minimum duration of the reservation. Otherwise, machine 1 will be available again on 15-10-2021 at 07:01.

  11. #11
    Registered User
    Join Date
    03-30-2017
    Location
    Brazil
    MS-Off Ver
    2019
    Posts
    54

    Re: Search 2 criteria "Reservation panel"

    Thank you very much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] If/IsNumber multiple search criteria. Does syntax accept "OR"?
    By onemoremile in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 08-03-2018, 05:36 PM
  2. Replies: 2
    Last Post: 07-24-2017, 02:19 AM
  3. Adding a "Take Me There" option to a Multiple Search criteria Macro ?
    By hans302 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-07-2017, 10:42 AM
  4. 7 nested IF statements with a SEARCH added IF(ISNUMBER(SEARCH({"INSUR","AP REFUND"}
    By michaelproctor001 in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 12-10-2013, 02:13 PM
  5. Replies: 0
    Last Post: 07-09-2009, 04:07 PM
  6. Creating Color Row "Control Panel"
    By SteveC in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-24-2006, 05:40 PM
  7. =IF(ISERROR(SEARCH("insurance",A125,1)),"","*")
    By cynichromantique in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-31-2006, 02:45 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1