Consulting

Results 1 to 4 of 4

Thread: Find the first cell in a column by criteria and replace with combobox value

  1. #1
    VBAX Regular
    Joined
    May 2009
    Posts
    76
    Location

    Find the first cell in a column by criteria and replace with combobox value

    How can I find the first cell in a column by criteria and then replace that with a userform combobox value.

    For instance, let’s say I have a column (D) with the following formula dragged down to each cell.
    =IF(C2="MP","Mike P","")

    And I wanted the first cell that meets the following criteria: “” in that column to be replaced with a userform combo box value (Player2) after the command button is clicked on.

    See attached worksheet.
    Attached Files Attached Files

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Dim r As Range, c As Range
    
    Set r = Sheets("sheet1").Range("a1").CurrentRegion.Columns("d").Cells
    
    For Each c In r
        If c.Value = "" Then
            c.Value = ComboBox1.Value
        End If
    Next

  3. #3
    VBAX Regular
    Joined
    May 2009
    Posts
    76
    Location
    Thanks for the code. How can I adjust it to fill in only the first ("") cell located. Not all of the cells ("").

    The user clicks on the submit button and the first cell that equals ("") should be filled with the combobox only. If the user clicks on the submit button again it would drop down to the next cell that equals ("") and so on.

  4. #4
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Insert this.

    Exit for
    or
    Exit sub

Posting Permissions

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