View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default UserForm code help needed.

THIS IS A CUT DOWN VERSION OF THE CODE YOU HAD AMENDED
USING THE SUGGESTIONS (Note the Function is included but
not shown in the code here):

Try this in a new workbook with 1 userform with 3
textboxes, and two buttons one to add teh value and 1 to
cancel the process.

You'll notice that it adds your data in each line going
down one after the other. The easiest way to prove it is
to run it (don't forget to include the Function code), by
just entering the letters of teh alphabet in order into
the first textbox only

'++++++++++++++++++++++++++++++++++++++++
Private Sub CommandButton1_Click()
Unload Me
End Sub

Private Sub Button_cancel_Click()
Unload Me
End Sub

Public Sub InputButton_Click()
'set up variables

Dim x As Integer
Dim y As String
Dim int_col As Integer
Dim int_row As Integer

Dim Title As String
Dim Firstname As String
Dim Surname As String

'fill variables with info from form

Title = TitleBox
Firstname = TxtFirstname
Surname = TxtSurname

Worksheets("sheet1").Select

int_col = 1
int_row = 1
Call Goto_Last("a1", int_col, int_row)

x = int_row + 1
y = "A" & x

Range(y).Select

Range(y).Value = Title
Range(y).Offset(0, 1).Value = Firstname
Range(y).Offset(0.2).Value = Surname


'this bit is to try and clear the form ready for the next
input
Unload UserForm1
UserForm1.Show


End Sub



-----Original Message-----
Thanks, Alan. Unfortunately, I'm an absolute beginner at

all this.
I've done what you suggested at point 1 (I think), but

don't know how
to specify the cell I want to start at. I've tried this -

ActiveCell("A2") = Title
ActiveCell.Offset(0, 1).Value = FirstName
ActiveCell.Offset(0, 2).Value = Surname
ActiveCell.Offset(0, 3).Value = Address1
ActiveCell.Offset(0, 4).Value = Address2
ActiveCell.Offset(0, 5).Value = Address3
ActiveCell.Offset(0, 6).Value = Address4
ActiveCell.Offset(0, 7).Value = Postcode
ActiveCell.Offset(0, 8).Value = Today
ActiveCell.Offset(0, 9).Value = ID
ActiveCell.Offset(0, 10).Value = form

And as for point 2, (and this is probably a dumb

question), where do I
put that code? Do I put it as a seperate module?

And if I'm specifying a start cell, surely each time the

program loops,
it'll start at the same place, overwriting the original

data? (That's
the problem I was having with my original code.)

Alan Hutchins wrote:
[b]There are a few things that would help:

1) you could specify the cell where you want to start
your process, and then select it as the activecell.

Then
use Activecell.Offset(0,1).value = x

where x is the value you wish to assign.

You just increase the offset number by 1 to move across
the columns, and it would be better to specifically

code
these, rather than increment them.

2) you seem to be relying on Excel determining the

active
row to produce the next empty row - this is not a
foolproof method. You would be better off determining

the
last used cell in the sheet where you are writing the
details, and then obtaining the rwo, incrementing by

one[color=blue]
and selecting the first cell on taht row - the function
below always works.

Call the function like this:

Call Goto_LAst("a1",1,1)

it will return the last cell address and the numeric
column and the number of the row also.

Function Goto_Last(strrange, int_col, int_row)
On Error Resume Next
application.ScreenUpdating = False
Cells(Cells.Find("*", Range("A1"), , , xlByRows,
xlPrevious).Row, _
Cells.Find("*", Range("A1"), , , xlByColumns,
xlPrevious).Column).Select
If Err.Number < 0 Then MsgBox "No data in sheet"
application.ScreenUpdating = True
strrange = ActiveCell.AddressLocal
int_col = ActiveCell.Column
int_row = ActiveCell.Row
End Function


Hope this is of use

Alan



---
Message posted from http://www.ExcelForum.com/

.