View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
madbloke[_7_] madbloke[_7_] is offline
external usenet poster
 
Posts: 1
Default UserForm code help needed.

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:[color=blue]
[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
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/