#1   Report Post  
Posted to microsoft.public.excel.misc
Mike Rogers
 
Posts: n/a
Default User form

Hi all,

I am trying to adapt the information from
http://www.contextures.com/xlUserForm01.html to make a userform for my
worksheet. I got everything working, almost!!! The form enters data in A2
of my sheet and I can't figure out how to make it enter it into the next
available cell in the range of F17:F50. There were alot of places I had to
change things in Debra's code to work for my form and I think I must have
done something wrong. Any help would be appreciated.
Here is the code that I have so far:

Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("DataInput")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

'check for a employee name
If Trim(Me.txtName.Value) = "" Then
Me.txtName.SetFocus
MsgBox "Please enter New Employee Name"
Exit Sub
End If

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtName.Value

'clear the data
Me.txtName.Value = ""

End Sub

Thanks
Mike Rogers
  #2   Report Post  
Posted to microsoft.public.excel.misc
Bob Phillips
 
Posts: n/a
Default User form

This bit of code

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

finds the last used row in column A (1), so c hange that to

'find first empty row in database
iRow = ws.Cells(Rows.Count, "F") _
.End(xlUp).Offset(1, 0).Row

and this bit copies it

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtName.Value

so change that to

'copy the data to the database
ws.Cells(iRow, "F").Value = Me.txtName.Value


Before the copy though, you need to increment iRow by one, as you have found
the last used cell, not the first free one.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Mike Rogers" wrote in message
...
Hi all,

I am trying to adapt the information from
http://www.contextures.com/xlUserForm01.html to make a userform for my
worksheet. I got everything working, almost!!! The form enters data in

A2
of my sheet and I can't figure out how to make it enter it into the next
available cell in the range of F17:F50. There were alot of places I had

to
change things in Debra's code to work for my form and I think I must have
done something wrong. Any help would be appreciated.
Here is the code that I have so far:

Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("DataInput")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

'check for a employee name
If Trim(Me.txtName.Value) = "" Then
Me.txtName.SetFocus
MsgBox "Please enter New Employee Name"
Exit Sub
End If

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtName.Value

'clear the data
Me.txtName.Value = ""

End Sub

Thanks
Mike Rogers



  #3   Report Post  
Posted to microsoft.public.excel.misc
Mike Rogers
 
Posts: n/a
Default User form

Bob,
Thanks for the help!! I can see now how it finds column F and the next
empty row. I made those two changes and it worked. I did not try to
increment iRow by one because I don't really know how or where to do that.
But bottom line...It works!!!
Thanks again for your help.

"Bob Phillips" wrote:

This bit of code

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

finds the last used row in column A (1), so c hange that to

'find first empty row in database
iRow = ws.Cells(Rows.Count, "F") _
.End(xlUp).Offset(1, 0).Row

and this bit copies it

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtName.Value

so change that to

'copy the data to the database
ws.Cells(iRow, "F").Value = Me.txtName.Value


Before the copy though, you need to increment iRow by one, as you have found
the last used cell, not the first free one.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Mike Rogers" wrote in message
...
Hi all,

I am trying to adapt the information from
http://www.contextures.com/xlUserForm01.html to make a userform for my
worksheet. I got everything working, almost!!! The form enters data in

A2
of my sheet and I can't figure out how to make it enter it into the next
available cell in the range of F17:F50. There were alot of places I had

to
change things in Debra's code to work for my form and I think I must have
done something wrong. Any help would be appreciated.
Here is the code that I have so far:

Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("DataInput")

'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row

'check for a employee name
If Trim(Me.txtName.Value) = "" Then
Me.txtName.SetFocus
MsgBox "Please enter New Employee Name"
Exit Sub
End If

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtName.Value

'clear the data
Me.txtName.Value = ""

End Sub

Thanks
Mike Rogers




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
user form question: text box to display result BigPig Excel Discussion (Misc queries) 0 February 28th 06 12:33 AM
user form question: text box to display result BigPig Excel Worksheet Functions 0 February 25th 06 08:17 PM
Example User Form Required robertguy Excel Discussion (Misc queries) 0 October 4th 05 02:25 PM
Print scrollable user form. cparsons Excel Discussion (Misc queries) 2 August 4th 05 04:45 PM
Data Entry Alert in User Form Kev Excel Discussion (Misc queries) 6 January 8th 05 03:01 PM


All times are GMT +1. The time now is 06:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"