Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Generate auto increment number from VB form


I am trying to design a simple task management spreadsheet where users
can insert new tasks via a VB form.

What I want to do is have the form auto insert an incremented number (I
want to be able to specifiy the first number) into the first cell. This
number will be the task ID number.

Any ideas?

Here is the code I have so far to insert the new row


Code:
--------------------
Private Sub CommandButton1_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Task_List")

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

'copy the data to the database
'auto increment number

' descrption
ws.Cells(iRow, 2).Value = Me.TextBox1.Value
' priority
ws.Cells(iRow, 3).Value = Me.ComboBox1.Value
' start date
ws.Cells(iRow, 4).Value = Me.TextBox2.Value
' due date
ws.Cells(iRow, 5).Value = Me.TextBox3.Value
' status
ws.Cells(iRow, 6).Value = Me.ComboBox3.Value
' category
ws.Cells(iRow, 7).Value = Me.ComboBox2.Value

'clear the data
Me.TextBox1.Value = ""
Me.ComboBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.ComboBox3.Value = ""
Me.ComboBox2.Value = ""
Me.TextBox1.SetFocus

End Sub
--------------------


--
john_t_h
------------------------------------------------------------------------
john_t_h's Profile: http://www.excelforum.com/member.php...fo&userid=4826
View this thread: http://www.excelforum.com/showthread...hreadid=402011

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Generate auto increment number from VB form

Maybe something like:

If iRow = 2 then 'first row of data
ws.Cells(iRow, 1).Value = 1000 'specified start value
else
ws.Cells(iRow, 1).Value = ws.Cells(iRow-1, 1).Value
End If

Hope this helps
Rowan

"john_t_h" wrote:


I am trying to design a simple task management spreadsheet where users
can insert new tasks via a VB form.

What I want to do is have the form auto insert an incremented number (I
want to be able to specifiy the first number) into the first cell. This
number will be the task ID number.

Any ideas?

Here is the code I have so far to insert the new row


Code:
--------------------
Private Sub CommandButton1_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Task_List")

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

'copy the data to the database
'auto increment number

' descrption
ws.Cells(iRow, 2).Value = Me.TextBox1.Value
' priority
ws.Cells(iRow, 3).Value = Me.ComboBox1.Value
' start date
ws.Cells(iRow, 4).Value = Me.TextBox2.Value
' due date
ws.Cells(iRow, 5).Value = Me.TextBox3.Value
' status
ws.Cells(iRow, 6).Value = Me.ComboBox3.Value
' category
ws.Cells(iRow, 7).Value = Me.ComboBox2.Value

'clear the data
Me.TextBox1.Value = ""
Me.ComboBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.ComboBox3.Value = ""
Me.ComboBox2.Value = ""
Me.TextBox1.SetFocus

End Sub
--------------------


--
john_t_h
------------------------------------------------------------------------
john_t_h's Profile: http://www.excelforum.com/member.php...fo&userid=4826
View this thread: http://www.excelforum.com/showthread...hreadid=402011


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Generate auto increment number from VB form

sorry should read

If iRow = 2 then 'first row of data
ws.Cells(iRow, 1).Value = 1000 'specified start value
else
ws.Cells(iRow, 1).Value = ws.Cells(iRow-1, 1).Value + 1
End If

Regards
Rowan

"Rowan" wrote:

Maybe something like:

If iRow = 2 then 'first row of data
ws.Cells(iRow, 1).Value = 1000 'specified start value
else
ws.Cells(iRow, 1).Value = ws.Cells(iRow-1, 1).Value
End If

Hope this helps
Rowan

"john_t_h" wrote:


I am trying to design a simple task management spreadsheet where users
can insert new tasks via a VB form.

What I want to do is have the form auto insert an incremented number (I
want to be able to specifiy the first number) into the first cell. This
number will be the task ID number.

Any ideas?

Here is the code I have so far to insert the new row


Code:
--------------------
Private Sub CommandButton1_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Task_List")

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

'copy the data to the database
'auto increment number

' descrption
ws.Cells(iRow, 2).Value = Me.TextBox1.Value
' priority
ws.Cells(iRow, 3).Value = Me.ComboBox1.Value
' start date
ws.Cells(iRow, 4).Value = Me.TextBox2.Value
' due date
ws.Cells(iRow, 5).Value = Me.TextBox3.Value
' status
ws.Cells(iRow, 6).Value = Me.ComboBox3.Value
' category
ws.Cells(iRow, 7).Value = Me.ComboBox2.Value

'clear the data
Me.TextBox1.Value = ""
Me.ComboBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.ComboBox3.Value = ""
Me.ComboBox2.Value = ""
Me.TextBox1.SetFocus

End Sub
--------------------


--
john_t_h
------------------------------------------------------------------------
john_t_h's Profile: http://www.excelforum.com/member.php...fo&userid=4826
View this thread: http://www.excelforum.com/showthread...hreadid=402011


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Generate auto increment number from VB form


Thanks Rowan, works a treat!

--
john_t_
-----------------------------------------------------------------------
john_t_h's Profile: http://www.excelforum.com/member.php...nfo&userid=482
View this thread: http://www.excelforum.com/showthread.php?threadid=40201

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
Auto Increment Number Thomas [PBD] Excel Discussion (Misc queries) 0 June 24th 08 10:01 PM
How to auto-number (increment) invoices in Excel? Pheasant Plucker® Excel Discussion (Misc queries) 1 September 8th 05 01:58 PM
Generate a unique form number quartz[_2_] Excel Programming 7 August 18th 05 01:26 PM
Generate number NOT using a form DavisC New Users to Excel 2 March 4th 05 01:21 AM
Auto-generate controls on form JJ[_5_] Excel Programming 1 August 7th 04 01:13 PM


All times are GMT +1. The time now is 08:21 AM.

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"