View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Incidental Incidental is offline
external usenet poster
 
Posts: 226
Default UserForms to populate cells in a worksheet

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