UserForms to populate cells in a worksheet

  • Thread starter Thread starter Office_Novice
  • Start date Start date
O

Office_Novice

I can do this in Word with bookmarks. is there a way do this in Excel?
 
The short answer is yes. But you need to amplify your requirement to allow
someone to offer a specific approach to the solution. You can use TextBox,
ListBox, ComboBox, Labels and even InputBoxes.
 
Sorry about that. I have a userForm with a label, a textBox, and a
CommandButton after clicking the commandButton i would like for the Text in
the TextBox to populate a specific Cell i.e. A1 then hide. any help would be
great code snippets would be ideal thanks.
 
Hi

You can get the data from the userform on to the sheet by referencing
the cell you want the data to go to. i.e.

'By referencing the activecell you can pass
'a value from a form to the worksheet though
'this can be a little dodgy if the wrong cell
'is selected it can lead to loss of data
ActiveCell.Value = TextBox1.Value

'This gives you a reference to the range A1
'from there you can pass the value to it
'using "Range" will allow you to pass use
'strings as you cell references which is very
'handy if you have declared a range that you
'wish to pass the data to i.e.
'Dim MyRng as Range
'set MyRng as Range("A1")
'Range(MyRng).Value=TextBox1.value
Range("A1").Value = TextBox1.Value

'If you know exactly which cell you are
'going to use you can do without adding
'"Range" at the start and just Giving the
'range reference in square brackets
[A1].Value = TextBox1.Value

'You can move in any direction using
'offset which will reference the cell that
'is by the amount of rows and columns that
'you declare, below would reference one cell
'to the right. This can also be used with
'negative numbers i.e. (-1,0)
[A1].Offset(0, 1).Value = TextBox2.Value

'Keeping offset in mind you can reference the
'next blank row by finding the end of the data
'working your way up the sheet until a value is
'found then setting the reference to offset by
'one row this will give you the next empty row
[A65535].End(xlUp).Offset(1, 0) = TextBox3.Value

'A more reliable way of making sure you get the
'correct cell is to reference it using "Cells()"
'this works by giving the row number and then
'the column number within the brackets
Cells(1, 1).Value = TextBox1.Value

'This would be the same as offsetting 1 cell
'to the right
Cells(1, 2).Value = TextBox2.Value

'You can also pass values to the reference "Cells" i.e.
'Dim a, b As Integer
'a = 10
'b = 10
'Cells(a, b).Value = TextBox1.Value

I hope this is of some help to you this is not the be all and end of
getting values from your form into your worksheet but it should give
you an idea of how it works.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top