Hello guys,
I need a little help with my code.
The final version of the code will be for renaming of column's headers through Userform.
I have a code to automatically generate TextBoxes of every used column (only the first row for each column) and insert the values to them.
Then I generated another (blank) TextBoxes, where I want to insert text and the text should rewrite original column's headers.
I don't know how to address to this generated TextBoxes.
Any help would be appreciated.
Here is my code:
Code
Private Sub TextBoxGenerate()
Dim lRow As Long, Ndx As Long
Dim tBox As MSForms.TextBox
Dim tBox2 As MSForms.TextBox
Dim lastColumn As Long
Const dDistHoriz As Double = 3
lastColumn = List1.Cells(1, Columns.Count).End(xlToLeft).Column
For Ndx = 1 To lastColumn
Set tBox = Me.Controls.Add(bstrProgID:="forms.textbox.1", Name:="tBoxEventsID", Visible:=True)
With tBox
.Width = 60
.Height = 20
.Left = 10
.Top = (Ndx - 0.8) * (30 + dDistHoriz) + 30
.Text = Range("A1").Offset(0, Ndx - 1).Value
End With
Next
For Ndx = 1 To lastColumn
Set tBox2 = Me.Controls.Add(bstrProgID:="forms.textbox.1", Name:="tBoxEventsID", Visible:=True)
With tBox2
.Width = 60
.Height = 20
.Left = tBox.Width + 25
.Top = (Ndx - 0.8) * (30 + dDistHoriz) + 30
Range("A3").Offset(0, Ndx - 1).Value = .Text
End With
Next
Me.Height = 400
Me.Width = tBox.Width + tBox2.Width + 58 + 50
Me.ScrollBars = fmScrollBarsVertical
Me.ScrollHeight = tBox.Top + tBox.Height + 5
End Sub
Sub ChangeColumnHeader_Click()
Dim lastColumn As Long
lastColumn = List1.Cells(1, Columns.Count).End(xlToLeft).Column
Controls("tBox2").Value = Cells(1, 3)
End Sub
Display More
[ATTACH=CONFIG]74025[/ATTACH]