VBA combobox data

KingGoku

New Member
Joined
Jul 12, 2023
Messages
31
Office Version
  1. 2016
Platform
  1. Windows
Hi there,

So currently I'm working on spreadsheet that will gather data from userform combo box. Each time data is entered from userform it is entered into new row that is entered at row 5. I want help with how do I code so that every 10th product selected in column B the 10th one is highlighted. Because 10th numbered product is on will be on the row 5 when which is the top row i m not sure how to do it. Also there might be different product selected in between so the product selection is not going to be 10 same product in row. I hope this description makes sense.
VBA Code:
Public SuppressChangeEvent As Boolean

Sub Button()
    Dim i As Integer
    Dim wb As Workbook: Set wb = ThisWorkbook
    Dim ws As Worksheet
    Dim WSheet As Worksheet
    Dim LastRow As Long
    Dim Row As Integer
    Dim Lot As String
    Dim Error As Boolean
    
Error = False

If FormSelectSht.TextBoxOperator1 = "" Then
    MsgBox "Please fill Operator Box"
    Error = True
End If

 If FormSelectSht.ComboBoxMachines = "" Then
    MsgBox "Please Select Machine"
    Error = True
End If

If FormSelectSht.ComboBoxPowder = "" Then
    MsgBox "Please Select Powder"
    Error = True
End If

If FormSelectSht.ComboBoxProduct = "" Then
    MsgBox "Please Select Product"
    Error = True
End If

If FormSelectSht.CBCrane = False Then
    MsgBox " Is the Crane off?"
    Error = True
End If

If FormSelectSht.CBVent = False Then
    MsgBox " Is the Vent on?"
    Error = True
End If

If Error Then
    SuppressChangeEvent = True
    Exit Sub
Else
    SuppressChangeEvent = False
End If




    
    For Each ws In wb.Sheets
        If ws.Name = FormSelectSht.ComboBoxMachines.Value Then Set WSheet = ws
    Next ws
    
 WSheet.Unprotect "Roto"
 
 
    
      With WSheet
        .Activate  'activating the sheet
        .Range("A5").EntireRow.Insert (xlDown)
         .Range("A5").EntireRow.ClearFormats     'Clear all formats from row 5
        .Range("A5:Q5").Font.Size = 14      'Increase font size
        'Insert a new row at 5 and shift everything down
       
        .Range("A5").Value = Date             'Insert date at A5
        .Range("B5").Value = FormSelectSht.ComboBoxProduct.Value    'Insert Combobox value at B5
       ' .Range("C5") = JulianDt(Date)
        .Range("C5").Value = FormSelectSht.TextBoxOperator1.Value
        .Range("D5").Value = FormSelectSht.TextBoxOperator2.Value
        .Range("E5").Value = FormSelectSht.TextBoxLot.Value
        .Range("I5").Value = FormSelectSht.CBVent.Value
        .Range("G5").Value = Time           'insert time at G5
        .Range("H5").Value = FormSelectSht.CBCrane.Value
        .Range("J5").Value = FormSelectSht.ComboBoxPowder.Value
        
      
      End With
       
       
       
   With WSheet.Range("L5").Validation
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="Accept,Reject"
        .IgnoreBlank = True
        .InCellDropdown = True
        .ShowInput = True
        .ShowError = True
    End With
 

    With Rows("5:5")
    .FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=$L$5=""Reject"""
    .FormatConditions(1).Interior.Color = 255
    .FormatConditions(1).StopIfTrue = False
    End With

FormSelectSht.ComboBoxProduct.Value = ""
FormSelectSht.TextBoxLot.Value = ""

WSheet.Protect "Roto"
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I hope this description makes sense.
Not to me. Can't tell if columns/rows are sheet columns/rows or combo columns/rows. Nor can I see how every 10th row comes in to play (if on a sheet) when 5 seems to be the operative row everywhere. If you're trying to highlight combo rows I doubt it's possible. If it's for the sheet, you could use conditional formatting in your column(s) with a cf formula like =MOD(ROW(),10)=0

Otherwise, in vba Mod function is used as [Number] Mod [Divisor]. You would use the Row number as [Number] and change backcolor of the cell with something like
If Range("A5").Row Mod 10 = 0 Then Range("A5").BackColor = vbYellow
 
Upvote 0
Not to me. Can't tell if columns/rows are sheet columns/rows or combo columns/rows. Nor can I see how every 10th row comes in to play (if on a sheet) when 5 seems to be the operative row everywhere. If you're trying to highlight combo rows I doubt it's possible. If it's for the sheet, you could use conditional formatting in your column(s) with a cf formula like =MOD(ROW(),10)=0

Otherwise, in vba Mod function is used as [Number] Mod [Divisor]. You would use the Row number as [Number] and change backcolor of the cell with something like
If Range("A5").Row Mod 10 = 0 Then Range("A5").BackColor = vbYellow
Sorry yeah it's confusing even i don't know how to phrase it.
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,953
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top