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
 
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
It works. Thanks so much. appreciate your help
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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