HelloKhritty
New Member
- Joined
- Jan 7, 2022
- Messages
- 9
- Office Version
- 2016
- 2013
- 2011
- 2010
- Platform
- Windows
Hi Mr Excel,
I am having a hard time creating this project for I am new using VBA.
My problem is, I am creating a worksheet using vb where cell 1 contains dropdown list that if you choose the item 1, only 6 characters will be allowed on cell 2. Else, if item 2 was chosen, only allow 9 characters in cell 2.
Cell range is until where data is available.
Here's my code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
'Column B
Dim Rng As Range
Set Rng = ws.Range("B2:B25") 'setting range of validation in worksheet (Column B, row2 - 25)
'Column A
Dim Courier As Range
Dim RowA As String
Set Courier = ws.Range("A2:A25") 'setting range for validation in worksheet (Column A)
If Courier.Value = "UPS" Then
'apply data validation
With Rng.Validation
.Delete
.Add Type:=xlValidateTextLength, AlertStyle:=xlValidAlertStop, Operator:=xlEqual, Formula1:="6"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = "Check Length"
.ErrorTitle = "Check #"
.ErrorMessage = "You can only enter a maximum of 6 characters only!"
.ShowInput = True
.ShowError = True
End With
ElseIf Courier.Value = "FedEx" Then
With Rng.Validation
.Delete
.Add Type:=xlValidateTextLength, AlertStyle:=xlValidAlertStop, Operator:=xlEqual, Formula1:="9"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = "Check Length"
.ErrorTitle = "Check #"
.ErrorMessage = "You can only enter a maximum of 9 characters only!"
.ShowInput = True
.ShowError = True
End With
End If
End Sub
sorry for the syntax errors I am new to this. Hope you can help MrExcel. Thank you.
I am having a hard time creating this project for I am new using VBA.
My problem is, I am creating a worksheet using vb where cell 1 contains dropdown list that if you choose the item 1, only 6 characters will be allowed on cell 2. Else, if item 2 was chosen, only allow 9 characters in cell 2.
Cell range is until where data is available.
Here's my code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
'Column B
Dim Rng As Range
Set Rng = ws.Range("B2:B25") 'setting range of validation in worksheet (Column B, row2 - 25)
'Column A
Dim Courier As Range
Dim RowA As String
Set Courier = ws.Range("A2:A25") 'setting range for validation in worksheet (Column A)
If Courier.Value = "UPS" Then
'apply data validation
With Rng.Validation
.Delete
.Add Type:=xlValidateTextLength, AlertStyle:=xlValidAlertStop, Operator:=xlEqual, Formula1:="6"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = "Check Length"
.ErrorTitle = "Check #"
.ErrorMessage = "You can only enter a maximum of 6 characters only!"
.ShowInput = True
.ShowError = True
End With
ElseIf Courier.Value = "FedEx" Then
With Rng.Validation
.Delete
.Add Type:=xlValidateTextLength, AlertStyle:=xlValidAlertStop, Operator:=xlEqual, Formula1:="9"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = "Check Length"
.ErrorTitle = "Check #"
.ErrorMessage = "You can only enter a maximum of 9 characters only!"
.ShowInput = True
.ShowError = True
End With
End If
End Sub
sorry for the syntax errors I am new to this. Hope you can help MrExcel. Thank you.