#1   Report Post  
Monty
 
Posts: n/a
Default forms

i have the following working within a macro:.

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtPart.Value
ws.Cells(iRow, 2).Value = Me.txtLoc.Value
ws.Cells(iRow, 3).Value = Me.txtDate.Value
ws.Cells(iRow, 4).Value = Me.txtQty.Value

Is there any way a can change this to do the following:- when i open the
form it moves to the next column, for example if i allocate cell AF 21 then
the next time i open the form it would go to cell AG21

Thanks

Monty
  #2   Report Post  
Monty
 
Posts: n/a
Default forms

Sorry the full macro is this

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

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

'check for a part number
If Trim(Me.txtPart.Value) = "" Then
Me.txtPart.SetFocus
MsgBox "Please enter a part number"
Exit Sub
End If

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtPart.Value
ws.Cells(iRow, 2).Value = Me.txtLoc.Value
ws.Cells(iRow, 3).Value = Me.txtDate.Value
ws.Cells(iRow, 4).Value = Me.txtQty.Value

'clear the data
Me.txtPart.Value = ""
Me.txtLoc.Value = ""
Me.txtDate.Value = ""
Me.txtQty.Value = ""
Me.txtPart.SetFocus


"Monty" wrote:

i have the following working within a macro:.

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtPart.Value
ws.Cells(iRow, 2).Value = Me.txtLoc.Value
ws.Cells(iRow, 3).Value = Me.txtDate.Value
ws.Cells(iRow, 4).Value = Me.txtQty.Value

Is there any way a can change this to do the following:- when i open the
form it moves to the next column, for example if i allocate cell AF 21 then
the next time i open the form it would go to cell AG21

Thanks

Monty

  #3   Report Post  
Dave Peterson
 
Posts: n/a
Default forms

Your code plops the entries from the userform into columns A:D.

This seems like a pretty usual layout for data like this.

But you could use the same kind of technique to find the next column:

Dim NextCol as long

with ws
nextcol = .cells(1,.columns.count).end(xltoleft).offset(0,1) .column
end with

But this finds the next available column in row 1.

I'm not sure how your code should know to look at row 21 (or any other row).

Monty wrote:

Sorry the full macro is this

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

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

'check for a part number
If Trim(Me.txtPart.Value) = "" Then
Me.txtPart.SetFocus
MsgBox "Please enter a part number"
Exit Sub
End If

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtPart.Value
ws.Cells(iRow, 2).Value = Me.txtLoc.Value
ws.Cells(iRow, 3).Value = Me.txtDate.Value
ws.Cells(iRow, 4).Value = Me.txtQty.Value

'clear the data
Me.txtPart.Value = ""
Me.txtLoc.Value = ""
Me.txtDate.Value = ""
Me.txtQty.Value = ""
Me.txtPart.SetFocus

"Monty" wrote:

i have the following working within a macro:.

'copy the data to the database
ws.Cells(iRow, 1).Value = Me.txtPart.Value
ws.Cells(iRow, 2).Value = Me.txtLoc.Value
ws.Cells(iRow, 3).Value = Me.txtDate.Value
ws.Cells(iRow, 4).Value = Me.txtQty.Value

Is there any way a can change this to do the following:- when i open the
form it moves to the next column, for example if i allocate cell AF 21 then
the next time i open the form it would go to cell AG21

Thanks

Monty


--

Dave Peterson
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
using forms in a shared workbook Dan23 Excel Worksheet Functions 3 August 9th 05 03:31 PM
Print out certain forms automatically Lost! Excel Discussion (Misc queries) 0 June 4th 05 08:49 PM
Forms that are modal in 97 are not modal in 2003 Old Car Excel Discussion (Misc queries) 1 April 27th 05 08:25 AM
how do I combine two forms with different size columns to make on. Morningside Excel Discussion (Misc queries) 3 April 17th 05 05:17 PM
Forms Toolbar vs. Control Toolbox vs. Data Validation for drop dow Scott Excel Discussion (Misc queries) 1 February 1st 05 01:51 PM


All times are GMT +1. The time now is 09:39 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"