VBA form data to specific cells

MNFPGE

New Member
Joined
Mar 5, 2018
Messages
8
Hi, I'm new to forms and a beginner on VBA, so struggling with a VBA to make a user form fill in specific cells in a sheet. I have created the form and now I want to get the data from the fields into the cells on the worksheet and if the cells in the worksheet have data in them for this to be shown in the form fields. I have set up a button in the worksheet to show the userform and I want a button on the userform to save the workbook once the fields have been filled in. Not all the fields will have data in them. I also want a button to close the form once the user has finished. Below shows the location I want the data to end up(Column C) and the names of the fields(Column B) in the form. I haven't really got any VBA so far that is worth posting as I'm lost to start with!:eek:

<b></b><table cellpadding="2.5px" rules="all" style=";background-color: rgb(255,255,255);border: 1px solid;border-collapse: collapse; border-color: rgb(187,187,187)"><colgroup><col width="25px" style="background-color: rgb(218,231,245)" /><col /></colgroup><thead><tr style=" background-color: rgb(218,231,245);text-align: center;color: rgb(22,17,32)"><th></th><th>B</th></tr></thead><tbody><tr ><td style="color: rgb(22,17,32);text-align: center;">83</td><td style="background-color: #C6E0B4;;">Rail Wall 1</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">84</td><td style="background-color: #C6E0B4;;">Rail Wall 2</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">85</td><td style="background-color: #C6E0B4;;">Rail Wall 3</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">86</td><td style="background-color: #C6E0B4;;">Left Wall 1</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">87</td><td style="background-color: #C6E0B4;;">Left Wall 2</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">88</td><td style="background-color: #C6E0B4;;">Left Wall 3</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">89</td><td style="background-color: #C6E0B4;;">Right Wall 1</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">90</td><td style="background-color: #C6E0B4;;">Right Wall 2</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">91</td><td style="background-color: #C6E0B4;;">Right Wall 3</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">92</td><td style="background-color: #C6E0B4;;">Opp Wall 1</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">93</td><td style="background-color: #C6E0B4;;">Opp Wall 2</td></tr><tr ><td style="color: rgb(22,17,32);text-align: center;">94</td><td style="background-color: #C6E0B4;;">Opp Wall 3</td></tr></tbody></table><p style="width:7.2em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid rgb(187,187,187);border-top:none;text-align: center;background-color: rgb(218,231,245);color: rgb(22,17,32)">Questions</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: rgb(255,255,255)" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: rgb(255,255,255);border-collapse: collapse; border-color: rgb(187,187,187)"><thead><tr style=" background-color: rgb(218,231,245);color: rgb(22,17,32)"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">B83</th><td style="text-align:left">Rail Wall 1</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">C83</th><td style="text-align:left"></td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">B84</th><td style="text-align:left">Rail Wall 2</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">C84</th><td style="text-align:left"></td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">B85</th><td style="text-align:left">Rail Wall 3</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">C85</th><td style="text-align:left"></td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">B86</th><td style="text-align:left">Left Wall 1</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">C86</th><td style="text-align:left"></td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">B87</th><td style="text-align:left">Left Wall 2</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">C87</th><td style="text-align:left"></td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">B88</th><td style="text-align:left">Left Wall 3</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">C88</th><td style="text-align:left"></td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">B89</th><td style="text-align:left">Right Wall 1</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">C89</th><td style="text-align:left"></td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">B90</th><td style="text-align:left">Right Wall 2</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">C90</th><td style="text-align:left"></td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">B91</th><td style="text-align:left">Right Wall 3</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">C91</th><td style="text-align:left"></td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">B92</th><td style="text-align:left">Opp Wall 1</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">C92</th><td style="text-align:left"></td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">B93</th><td style="text-align:left">Opp Wall 2</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">C93</th><td style="text-align:left"></td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">B94</th><td style="text-align:left">Opp Wall 3</td></tr><tr><th width="10px" style=" background-color: rgb(218,231,245);color: rgb(22,17,32)">C94</th><td style="text-align:left"></td></tr></tbody></table></td></tr></table><br />
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,306
Well to close a Userform you need a button on the Userform
And the code:
Unload Me

To send data to the sheet you would need code like this:

Sheets(1).cells(1,1).value=Textbox1.value

This is a simplistic answer.

You would need to modify to your needs.
 

MNFPGE

New Member
Joined
Mar 5, 2018
Messages
8
Thanks My Aswer Is This and James 006. Working through what you have both posted and hopefully I'll get it. Good learning's anyway!
 

James006

Well-known Member
Joined
Apr 4, 2009
Messages
3,680
All the Best ...in you new adventure ...
 

MNFPGE

New Member
Joined
Mar 5, 2018
Messages
8
Ok, so here's what I've come up with, I've kept it brief until I get it working. It opens and closes the form alright but doesn't unload the data into the worksheet. I'm obviously missing something but I'm not sure what...

Code:
Private Sub CarWallBraceUserForm()

UserForm3.Show


End Sub
Private Sub SaveWallBraceButton_Click()
Dim WS As Worksheet
Dim Sizes As Long
Set WS = Worksheets("Questions")
With WS
Sheet("Questions").Cells(85, 3).Value = RailPosn1.Value
Sheet("Questions").Cells(86, 3).Value = RailPosn2.Value


End Sub


Private Sub CloseFormBtn_Click()
Unload Me
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,440
Office Version
365
Platform
Windows
How about
Code:
Private Sub SaveWallBraceButton_Click()
   Dim WS As Worksheet
   Dim Sizes As Long
   Set WS = Worksheets("Questions")
   With WS
      .Cells(85, 3).Value = RailPosn1.Value
      .Cells(86, 3).Value = RailPosn2.Value
   End With

End Sub
 

MNFPGE

New Member
Joined
Mar 5, 2018
Messages
8
Thanks Fluff, tried that but it doesn't work either. I'm not sure if I've got something simple wrong, like Text Box names but I've checked them so it's not them. Is there something else obvious that I've missed? Thanks again.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,440
Office Version
365
Platform
Windows
That code should be putting the values from the textboxes into C85 & C86 on the Questions sheet.
Do you get any error messages?
 

MNFPGE

New Member
Joined
Mar 5, 2018
Messages
8
The form opens, but the data doesn't unload to the cells.
Code:
Private Sub CarWallBraceUserForm()

UserForm3.Show


End Sub
Private Sub SaveWallBraceButton_Click()
   Dim WS As Worksheet
   Dim Sizes As Long
   Set WS = Worksheets("Questions")
   With WS
      Cells(85, 3).Value = RailPosn1.Value
      Cells(86, 3).Value = RailPosn2.Value
   End With


End Sub


Private Sub CloseFormBtn_Click()
Unload Me
End Sub


Private Sub UserForm_Click()


End Sub
 

Forum statistics

Threads
1,082,601
Messages
5,366,571
Members
400,902
Latest member
fathima

Some videos you may like

This Week's Hot Topics

Top