I have 2 columns, one with a last name the other with a first name. I need to concatenate them into a third column (last name, first name) in a way that when I add a new name the third column will automatically update with the concatenated name. It needs to be done using VBA, but I haven't the slightest clue where to start.
Also the third column will be loaded into a listbox so that when I select a name a a number they have been assigned will pop up as a label caption. Any one know of anyway to do this? Hope that kind of all made some sense to somebody. Thanks for taking the time
VBA Concatenate and listbox
-
-
-
Re: VBA Concatenate and listbox
Hello bellshell, and welcome to the forum!
For the first question, right-click on the sheet tab, view code. Paste this in.
Code
Display MorePrivate Sub Worksheet_Change(ByVal Target As Range) Dim c As Range Dim iRow As Long Dim intRange As Range 'Assumes that we're watching cells in col A & B, but have header info in row 1 Set intRange = Intersect(Target, Range("A:B")) If intRange Is Nothing Then Exit Sub Application.ScreenUpdating = False Application.EnableEvents = False For Each c In intRange iRow = c.Row If iRow <> 1 Then Cells(iRow, "C").Value = Cells(iRow, "B").Value & ", " & Cells(iRow, "A").Value End If Next c Application.EnableEvents = True Application.ScreenUpdating = True End Sub
Adjust the column references if necessary. For the latter question, we'll need a lot more information. Where is the listbox, how do you want the information loaded? Could we just use a dynamic range that populates the listbox?
-
Re: VBA Concatenate and listbox
Thanks that helps a lot! I was able to kinda figure out what I wanted to do with the second part of that. Appreciate it!
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!