Hello,
Currently the code below perform the proper function (Capitalize the first letter) after entering in the column in the pop up window. Depending on the files, the column containing the "First Name" and "Last Name" may be in A:B or D and E etc. Is there a way to use this proper function on the column name "First Name" and "Last Name" rather than having the indicating which cloumn to perform the proper function?
Please correct the code above to run the proper function on the column with the name "First Name" and "Last Name" without having enter the columns in the text box window. This way I dont have to look for the column "First Name" and "Last Name" and entering the column in the pop up text/window. Thanks!
Currently the code below perform the proper function (Capitalize the first letter) after entering in the column in the pop up window. Depending on the files, the column containing the "First Name" and "Last Name" may be in A:B or D and E etc. Is there a way to use this proper function on the column name "First Name" and "Last Name" rather than having the indicating which cloumn to perform the proper function?
Code:
Sub Proper()
Dim varMyArrayList As Variant, _
varMyArrayItem As Variant
Dim intMyArrayCount As Integer
Dim strFirstNameCol As String, _
strLastNameCol As String
Dim lngRowStart As Long, _
lngRowEnd As Long
Dim rngFirstName As Range, _
rngLastName As Range, _
rngCell As Range
varMyArrayList = InputBox("Please enter the columns containing the first and last names (respectively) separated by a single comma i.e." & vbNewLine & "C,D", "Proper Case Converter")
'Quit the routinue if the user has clicked the button or _
not put a comma between the column letters.
If varMyArrayList = "" Or InStr(varMyArrayList, ",") = 0 Then Exit Sub
varMyArrayItem = Split(varMyArrayList, ",") 'Splits words by a comma
lngRowStart = 2 'Assumed starting row number. Change if needed.
For intMyArrayCount = 0 To UBound(varMyArrayItem)
If intMyArrayCount = 0 Then
strFirstNameCol = StrConv(CStr(varMyArrayItem(intMyArrayCount)), vbUpperCase)
Else
strLastNameCol = StrConv(CStr(varMyArrayItem(intMyArrayCount)), vbUpperCase)
End If
Next intMyArrayCount
'Set the 'rngFirstName' range and then convert each cell therein to ProperCase.
lngRowEnd = Cells(Rows.Count, strFirstNameCol).End(xlUp).Row
Set rngFirstName = Range(strFirstNameCol & lngRowStart & ":" & strFirstNameCol & lngRowEnd)
Application.ScreenUpdating = False
For Each rngCell In rngFirstName
rngCell.Value = StrConv(rngCell.Value, vbProperCase)
Next rngCell
Application.ScreenUpdating = True
'Set the 'rngLastName' range and then convert each cell therein to ProperCase.
lngRowEnd = Cells(Rows.Count, strLastNameCol).End(xlUp).Row
Set rngLastName = Range(strLastNameCol & lngRowStart & ":" & strLastNameCol & lngRowEnd)
Application.ScreenUpdating = False
For Each rngCell In rngLastName
rngCell.Value = StrConv(rngCell.Value, vbProperCase)
Next rngCell
Application.ScreenUpdating = True
End Sub
Please correct the code above to run the proper function on the column with the name "First Name" and "Last Name" without having enter the columns in the text box window. This way I dont have to look for the column "First Name" and "Last Name" and entering the column in the pop up text/window. Thanks!
Last edited: