+ Reply to Thread
Results 1 to 10 of 10

Change cells in row based on row of Combobox selection

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Change cells in row based on row of Combobox selection

    Good morning,

    Can anyone see what is wrong with my code? I am using the name identified in the combobox (cmbPS) to identify the row and then change the resulting cells. I keep getting an application defined or object defined error highlighting the row marked
    Cells(cmbPS.ListIndex, 66) = "OFF"
    The entire code:

    If chbMonday.Value = True Then
        Cells(cmbPS.ListIndex, 66) = "WORK"
        Cells(cmbPS.ListIndex, 67) = Me.cmbStartTime.Value
        Cells(cmbPS.ListIndex, 68) = Me.cmb1stBreakTime.Value
        Cells(cmbPS.ListIndex, 69) = Me.cmbLunchTime.Value
        Cells(cmbPS.ListIndex, 70) = Me.cmb2ndBreakTime.Value
        Cells(cmbPS.ListIndex, 71) = Me.cmbEndTime.Value
        Else
        Cells(cmbPS.ListIndex, 66) = "OFF"
        Range("BO7:BS7") = ""
    End If
    Thanks

    M

  2. #2
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change cells in row based on row of Combobox selection

    Any ideas?

  3. #3
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change cells in row based on row of Combobox selection

    PArtially fixed using the following code:

    If chbMonday.Value = True Then
        Cells(cmbPS.ListIndex + 7, 66) = "WORK"
        Cells(cmbPS.ListIndex + 7, 67) = Me.cmbStartTime.Value
        Cells(cmbPS.ListIndex + 7, 68) = Me.cmb1stBreakTime.Value
        Cells(cmbPS.ListIndex + 7, 69) = Me.cmbLunchTime.Value
        Cells(cmbPS.ListIndex + 7, 70) = Me.cmb2ndBreakTime.Value
        Cells(cmbPS.ListIndex + 7, 71) = Me.cmbEndTime.Value
        Else
        Cells(cmbPS.ListIndex + 7, 66) = "OFF"
        Range("BO:BS").Rows(cmbPSListIndex + 7) = ""
    End If
    Problem now is that it's updating the right columns but the wrong rows. Is my cmbPSListIndex + 7 incorrect in defining the row of the selected value from the combobox (the list starts 7 rows down on the spreadsheet)?

  4. #4
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change cells in row based on row of Combobox selection

    Any ideas?

  5. #5
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    867

    Re: Change cells in row based on row of Combobox selection

    Hi ! Can't you upload a sample file? (after striping off the sensible data)
    .. and don't forget to have fun!
    Bogdan.

    mark SOLVED and Add Reputation if my answer pleases you

  6. #6
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change cells in row based on row of Combobox selection

    Sorry I can't post the file, I think it has something to do with this line being incorrect:

    Range("BO:BS").Rows(cmbPSListIndex) = ""

  7. #7
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    867

    Re: Change cells in row based on row of Combobox selection

    there is a dot missing there...
    if that is the error it should be
    Range("BO:BS").Rows(cmbPS.ListIndex) = ""
    if not, try to find the cmbPS.ListIndex value
    put a msgbox cmbPS.ListIndex before that line. (debug.print cmbPS.ListIndex works also if you have the Immediate Window enabled (Ctrl+G)

  8. #8
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change cells in row based on row of Combobox selection

    Ok I pinpointed the issue, it's because cmBPS is creating unique values from PSList which has duplicate entries:

    Dim MyUniqueList As Variant, i As Long
        With Me.cmbPS
            .Clear ' clear the combobox content
            MyUniqueList = UniqueItemList(Range("PSList"), True)
            For i = 1 To UBound(MyUniqueList)
                .AddItem MyUniqueList(i)
            Next i
            .ListIndex = 0 ' select the first item
        End With
    As a result, cmbPS.ListIndex is not equal to PSList.ListIndex

    How should I go about fixing this?

  9. #9
    Forum Contributor
    Join Date
    08-13-2014
    Location
    Chicago
    MS-Off Ver
    2013
    Posts
    209

    Re: Change cells in row based on row of Combobox selection

    OK I fixed that but for some reason it's still changing the incorrect rows.

  10. #10
    Valued Forum Contributor bulina2k's Avatar
    Join Date
    11-20-2012
    Location
    Urziceni, Ialomita, Romania
    MS-Off Ver
    2019 and 365
    Posts
    867

    Re: Change cells in row based on row of Combobox selection

    i have no ideea untill i see the entire code BUT you can try :
    Dim MyUniqueList As Variant, i As Long
        With Me.cmbPS
            .Clear ' clear the combobox content
            MyUniqueList = Range("PSList")
            For i = 1 To UBound(MyUniqueList)
                .AddItem MyUniqueList(i, 1)
            Next i
            .ListIndex = 0 ' select the first item
        End With

+ 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. Change Userform fields based on combobox selection
    By vikrampnz in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-04-2014, 06:57 AM
  2. Change Userform Label based on ComboBox Selection
    By rbyrd023 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-02-2014, 09:25 AM
  3. [SOLVED] Change Labels in Userform based on selection in ComboBox
    By johnw993 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 01-03-2013, 10:52 PM
  4. Change label captions based on combobox selection
    By alter54 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-07-2012, 06:02 PM
  5. [SOLVED] Change Worksheet based on ComboBox selection
    By dagindi in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-15-2012, 10:19 AM

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