Hi I need to simplify my code. Ive got a user form with 256 text boxes on, one for each column.
I've named the text boxes "TbA", TbB", "TbC" etc to corespond to the column names.
I've then got another text box named "A", "B", "C" etc which fills with the cell value from the current row.
Is there a way of looping these instead?
Private Sub CBNames_Change()
Dim lRw As Long
With Me
lRw = .CBNames.ListIndex + 2 '<-add 2 to allow for header row & ListIndex starts at zero
.A.Value = Sheets("Main").Cells(lRw, 1).Value
.C.Value = Sheets("Main").Cells(lRw, 3).Value
.D.Value = Sheets("Main").Cells(lRw, 4).Value
.E.Value = Sheets("Main").Cells(lRw, 5).Value
.F.Value = Sheets("Main").Cells(lRw, 6).Value
'etc
End With
End Sub
Bookmarks