VBA form data to specific cells

MNFPGE

New Member
Joined
Mar 5, 2018
Messages
10
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 />
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,762
Office Version
2013
Platform
Windows
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
10
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
10
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
42,903
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
10
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
42,903
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
10
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
 

Watch MrExcel Video

Forum statistics

Threads
1,102,778
Messages
5,488,814
Members
407,658
Latest member
Arias610

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top