FryGirl
Well-known Member
- Joined
- Nov 11, 2008
- Messages
- 1,368
- Office Version
- 365
- 2016
- Platform
- Windows
In VBA I would like to have a Worksheet_Change event which when somebody types in a value in column A the macro would do two things.
First, check to make sure the value ends in a period and then indent the value based on the number of periods found?
This is what I have so far...it checks for the ending period and indents, but not sure how to return the number of periods which I would like to use to replace the hard coded IndentLevel. Is this the right way to go or is there a better way?
First, check to make sure the value ends in a period and then indent the value based on the number of periods found?
This is what I have so far...it checks for the ending period and indents, but not sure how to return the number of periods which I would like to use to replace the hard coded IndentLevel. Is this the right way to go or is there a better way?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As String
If Target.Column <> 1 Then Exit Sub
i = Right(Target.Value, 1)
If i = "." Then
MsgBox Len(Split(Target.Value)(0))
Range(Target.Address).IndentLevel = 2
Else
MsgBox "Please enter a number which ends in a period", vbInformation
End If
End Sub