Hi all, was working on this problem AGES ago, and could never find a simple solution. i'm SURE there has to be an easy way to do this, it would only make sense given the scenario.
Scenario:
Userform with 5 x textboxes.
a NAMED 5 column table "Table1" that has headers, obviously real data starts from row 2 eg:
[TABLE="width: 500"]
<tbody>[TR]
[TD]header1
[/TD]
[TD]header2
[/TD]
[TD]header3
[/TD]
[TD]header4
[/TD]
[TD]header5
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]a
[/TD]
[TD]1q
[/TD]
[TD]11
[/TD]
[TD]1
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]b
[/TD]
[TD]2w
[/TD]
[TD]22
[/TD]
[TD]0
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]c
[/TD]
[TD]3e
[/TD]
[TD]33
[/TD]
[TD]0
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I want to write code that can read what the header is and input the data under that header regardless if i add other columns in the future or move them etc. I want this to be as futureproof as possible.
Also, since i started making this userform about 18 months ago (the same time i started learning VBA from a textbook) and am only now being asked to finish it, I've forgotten how to do a whole lot of stuff... AND I made it more complicated by not having the table start on cell A1, it actually starts at about B5
something along the logic of:
private sub Submit_Click()
Table1([findRowWithHeader = "header1"] & [nextEmptyRow]).Value = TextBox1.Value
Table1([findRowWithHeader = "header2"] & [nextEmptyRow]).Value = TextBox2.Value
Table1([findRowWithHeader = "header3"] & [nextEmptyRow]).Value = TextBox3.Value
Table1([findRowWithHeader = "header4"] & [nextEmptyRow]).Value = TextBox4.Value
Table1([findRowWithHeader = "header5"] & [nextEmptyRow]).Value = TextBox5.Value
end sub
I was hoping for a way to call the table specifically, and therefore manipulate it without having to consider where the table sits on the sheet.
Thanks heaps everyone.
Scenario:
Userform with 5 x textboxes.
a NAMED 5 column table "Table1" that has headers, obviously real data starts from row 2 eg:
[TABLE="width: 500"]
<tbody>[TR]
[TD]header1
[/TD]
[TD]header2
[/TD]
[TD]header3
[/TD]
[TD]header4
[/TD]
[TD]header5
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]a
[/TD]
[TD]1q
[/TD]
[TD]11
[/TD]
[TD]1
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]b
[/TD]
[TD]2w
[/TD]
[TD]22
[/TD]
[TD]0
[/TD]
[/TR]
[TR]
[TD]3
[/TD]
[TD]c
[/TD]
[TD]3e
[/TD]
[TD]33
[/TD]
[TD]0
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I want to write code that can read what the header is and input the data under that header regardless if i add other columns in the future or move them etc. I want this to be as futureproof as possible.
Also, since i started making this userform about 18 months ago (the same time i started learning VBA from a textbook) and am only now being asked to finish it, I've forgotten how to do a whole lot of stuff... AND I made it more complicated by not having the table start on cell A1, it actually starts at about B5
something along the logic of:
private sub Submit_Click()
Table1([findRowWithHeader = "header1"] & [nextEmptyRow]).Value = TextBox1.Value
Table1([findRowWithHeader = "header2"] & [nextEmptyRow]).Value = TextBox2.Value
Table1([findRowWithHeader = "header3"] & [nextEmptyRow]).Value = TextBox3.Value
Table1([findRowWithHeader = "header4"] & [nextEmptyRow]).Value = TextBox4.Value
Table1([findRowWithHeader = "header5"] & [nextEmptyRow]).Value = TextBox5.Value
end sub
I was hoping for a way to call the table specifically, and therefore manipulate it without having to consider where the table sits on the sheet.
Thanks heaps everyone.