insert new row and insert data validation.

KingGoku

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

need help with auto adding data validation everytime new row has been inserted.
Data validation to be "Accept or Reject". if cell is reject whole row to be rejected and highlighted red.
VBA Code:
      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
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Attachments

  • Screenshot 2023-10-03 150613.png
    Screenshot 2023-10-03 150613.png
    14.9 KB · Views: 21
Upvote 0
How about this?

VBA Code:
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").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

    ' Check if cell L5 has the value "Rejected" and apply conditional formatting to the entire row
    If .Range("L5").Value = "Rejected" Then
        .Range("L5").EntireRow.FormatConditions.Add Type:=xlExpression, Formula1:="=$L5=""Reject"""
        .Range("L5").EntireRow.FormatConditions(1).Interior.Color = RGB(255, 0, 0)
    End If
End With
 
Last edited:
Upvote 0
How about this?

VBA Code:
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").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

    ' Check if cell L5 has the value "Rejected" and apply conditional formatting to the entire row
    If .Range("L5").Value = "Rejected" Then
        .Range("L5").EntireRow.FormatConditions.Add Type:=xlExpression, Formula1:="=$L5=""Reject"""
        .Range("L5").EntireRow.FormatConditions(1).Interior.Color = RGB(255, 0, 0)
    End If
End With
Doesn't work because everytime new row get inserted Data validation moves down as well and new row doesn't have data but not drop down data validation.
 
Upvote 0
Is column L supposed to be a drop-down list validation with values "Accept" & "Reject"?
 
Upvote 0
How about this?

VBA Code:
      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
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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