Transcribe the names from column A to column B while making the first letter a capital letter.
Solved Exercise
Exercise Solving
In this solution, we segregate the first letter of the name and we make it a capital letter. Subsequently combine it again with the rest of the name.
-
Start by declaring the variables and finding the last data entry in the worksheet
Dim LastRow As Long
Dim CellVal As String
Dim FirstLett As String
Dim NameLen As Integer
Dim EndName As String
Dim Name As String
Dim i As Integer
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
-
Define the size of the name with the Len function. Determine the first letter with the Left function and make it a capital letter with the Ucase function. Subsequently combine the capital letter with the rest of the name
For i = 3 To LastRow
CellVal = Cells(i, 1).Value
NameLen = Len(CellVal)
FirstLett = Left(CellVal, 1)
FirstLett = UCase(FirstLett)
EndName = Right(CellVal, NameLen - 1)
Name = FirstLett & EndName
Cells(i, 2).Value = Name
Next i
Consolidated Answer
Sub Solution()
Dim LastRow As Long
Dim CellVal As String
Dim FirstLett As String
Dim NameLen As Integer
Dim EndName As String
Dim Name As String
Dim i As Integer
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 3 To LastRow
CellVal = Cells(i, 1).Value
NameLen = Len(CellVal)
FirstLett = Left(CellVal, 1)
FirstLett = UCase(FirstLett)
EndName = Right(CellVal, NameLen - 1)
Name = FirstLett & EndName
Cells(i, 2).Value = Name
Next i
End Sub
SuperExcelVBA.com is learning website. Examples might be simplified to improve reading and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. All Rights Reserved.
Excel ® is a registered trademark of the Microsoft Corporation.
© 2024 SuperExcelVBA | ABOUT