In a database, the clients' first name and surname are in distinct worksheets. Link the first name and surname from those worksheets to aquire the full name of the clients in on single worksheet.
Solved Exercise
Exercise Solving
Assuming that every name in a worksheet will match a surname in another worksheet, we can solve the exercise with only one loop.
-
We start by declaring the variables and find the last data entry in the "Name" Worksheets. Be careful with missing values
Dim FirstName As String
Dim Surname As String
Dim FullName As String
Dim UltLinha As Long
Dim i As Integer
LastRow = Sheets("First_Name").Cells(2, 1).End(xlDown).Row
-
We then make a loop For Next until the last available found data and include within the loop the desired worksheet to output the results
For i = 3 To LastRow
FirstName = Sheets("First_Name").Cells(i, 1).Value
Surname = Sheets("Surname").Cells(i, 1).Value
FullName = FirstName & " " & Surname
Sheets("Full_Name").Cells(i, 1).Value = FullName
Next i
Consolidated Answer
Sub Solution()
Dim FirstName As String
Dim Surname As String
Dim FullName As String
Dim UltLinha As Long
Dim i As Integer
LastRow = Sheets("First_Name").Cells(2, 1).End(xlDown).Row
For i = 3 To LastRow
FirstName = Sheets("First_Name").Cells(i, 1).Value
Surname = Sheets("Surname").Cells(i, 1).Value
FullName = FirstName & " " & Surname
Sheets("Full_Name").Cells(i, 1).Value = FullName
Next i
Sheets("Full_Name").Activate
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