Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
D D is offline
external usenet poster
 
Posts: 121
Default No Duplicates Allowed

I have a Userform which updates a worksheet with the following code. I would
like it to check to see if the txtOrderNumber has already been entered in the
MasterList before copying the data to the MasterList with a message that lets
the user know that the Order Number has already been used.

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

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

'Check for a Order number
If Trim(Me.txtOrderNumber.Value) = "" Then
Me.txtOrderNumber.SetFocus
MsgBox "Please enter the Order Number"
Exit Sub
End If

'copy the data to MasterList
ws.Cells(iRow, 1).Value = Me.txtOrderStatus.Value
ws.Cells(iRow, 2).Value = Me.txtOrderNumber.Value
ws.Cells(iRow, 5).Value = Me.txtOrderDate.Value

'Clear the form
Me.txtOrderStatus.Value = ""
Me.txtOrderNumber.Value = ""
Me.txtOrderDate.Value = ""

Me.txtOrderStatus.SetFocus

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default No Duplicates Allowed


'--
Private Sub CmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Dim vStatus As Variant
Dim rng As Range
Set ws = Worksheets("MasterList")

'Find first empty row in MasterList
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
Set rng = ws.Range(ws.Cells(1, 2), ws.Cells(iRow, 2))

'Check for a Order number
If Trim(Me.txtOrderNumber.Value) = "" Then
Me.txtOrderNumber.SetFocus
MsgBox "Please enter the Order Number"
Exit Sub
End If

vStatus = Application.Match(CDbl(Trim(Me.txtOrderNumber.Valu e)), rng, 0)
If IsError(vStatus) Then
'copy the data to MasterList
ws.Cells(iRow, 1).Value = Me.txtOrderStatus.Value
ws.Cells(iRow, 2).Value = Me.txtOrderNumber.Value
ws.Cells(iRow, 5).Value = Me.txtOrderDate.Value
Else
MsgBox "found in row " & vStatus
End If

'Clear the form
Me.txtOrderStatus.Value = ""
Me.txtOrderNumber.Value = ""
Me.txtOrderDate.Value = ""

Me.txtOrderStatus.SetFocus
'Me.Hide
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)





"D"
wrote in message
I have a Userform which updates a worksheet with the following code. I would
like it to check to see if the txtOrderNumber has already been entered in the
MasterList before copying the data to the MasterList with a message that lets
the user know that the Order Number has already been used.

Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("MasterList")
'Find first empty row in MasterList
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'Check for a Order number
If Trim(Me.txtOrderNumber.Value) = "" Then
Me.txtOrderNumber.SetFocus
MsgBox "Please enter the Order Number"
Exit Sub
End If
'copy the data to MasterList
ws.Cells(iRow, 1).Value = Me.txtOrderStatus.Value
ws.Cells(iRow, 2).Value = Me.txtOrderNumber.Value
ws.Cells(iRow, 5).Value = Me.txtOrderDate.Value
'Clear the form
Me.txtOrderStatus.Value = ""
Me.txtOrderNumber.Value = ""
Me.txtOrderDate.Value = ""
Me.txtOrderStatus.SetFocus
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default No Duplicates Allowed

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

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

'Check for a Order number
If Trim(Me.txtOrderNumber.Value) = "" Then
Me.txtOrderNumber.SetFocus
MsgBox "Please enter the Order Number"
Exit Sub
End If

if application.countif(ws.range("a:a"),me.txtordernum ber.value) 0 then
'it's already there
'msgbox and beep???
else
'copy the data to MasterList
ws.Cells(iRow, 1).Value = Me.txtOrderStatus.Value
ws.Cells(iRow, 2).Value = Me.txtOrderNumber.Value
ws.Cells(iRow, 5).Value = Me.txtOrderDate.Value

'Clear the form
Me.txtOrderStatus.Value = ""
Me.txtOrderNumber.Value = ""
Me.txtOrderDate.Value = ""
end if

Me.txtOrderStatus.SetFocus

End Sub

untested, uncompiled--watch for typos.

D wrote:

I have a Userform which updates a worksheet with the following code. I would
like it to check to see if the txtOrderNumber has already been entered in the
MasterList before copying the data to the MasterList with a message that lets
the user know that the Order Number has already been used.

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

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

'Check for a Order number
If Trim(Me.txtOrderNumber.Value) = "" Then
Me.txtOrderNumber.SetFocus
MsgBox "Please enter the Order Number"
Exit Sub
End If

'copy the data to MasterList
ws.Cells(iRow, 1).Value = Me.txtOrderStatus.Value
ws.Cells(iRow, 2).Value = Me.txtOrderNumber.Value
ws.Cells(iRow, 5).Value = Me.txtOrderDate.Value

'Clear the form
Me.txtOrderStatus.Value = ""
Me.txtOrderNumber.Value = ""
Me.txtOrderDate.Value = ""

Me.txtOrderStatus.SetFocus

End Sub


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
D D is offline
external usenet poster
 
Posts: 121
Default No Duplicates Allowed


Thank You very much. Place your code into my sheet and I am having one
problem:

It doesn't like the "MsgBox "found in row " & vStatus" portion.

Any thoughts?

(By the way, you are going to make me look like a hero!!!)

"Jim Cone" wrote:


'--
Private Sub CmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Dim vStatus As Variant
Dim rng As Range
Set ws = Worksheets("MasterList")

'Find first empty row in MasterList
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
Set rng = ws.Range(ws.Cells(1, 2), ws.Cells(iRow, 2))

'Check for a Order number
If Trim(Me.txtOrderNumber.Value) = "" Then
Me.txtOrderNumber.SetFocus
MsgBox "Please enter the Order Number"
Exit Sub
End If

vStatus = Application.Match(CDbl(Trim(Me.txtOrderNumber.Valu e)), rng, 0)
If IsError(vStatus) Then
'copy the data to MasterList
ws.Cells(iRow, 1).Value = Me.txtOrderStatus.Value
ws.Cells(iRow, 2).Value = Me.txtOrderNumber.Value
ws.Cells(iRow, 5).Value = Me.txtOrderDate.Value
Else
MsgBox "found in row " & vStatus
End If

'Clear the form
Me.txtOrderStatus.Value = ""
Me.txtOrderNumber.Value = ""
Me.txtOrderDate.Value = ""

Me.txtOrderStatus.SetFocus
'Me.Hide
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)





"D"
wrote in message
I have a Userform which updates a worksheet with the following code. I would
like it to check to see if the txtOrderNumber has already been entered in the
MasterList before copying the data to the MasterList with a message that lets
the user know that the Order Number has already been used.

Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("MasterList")
'Find first empty row in MasterList
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
'Check for a Order number
If Trim(Me.txtOrderNumber.Value) = "" Then
Me.txtOrderNumber.SetFocus
MsgBox "Please enter the Order Number"
Exit Sub
End If
'copy the data to MasterList
ws.Cells(iRow, 1).Value = Me.txtOrderStatus.Value
ws.Cells(iRow, 2).Value = Me.txtOrderNumber.Value
ws.Cells(iRow, 5).Value = Me.txtOrderDate.Value
'Clear the form
Me.txtOrderStatus.Value = ""
Me.txtOrderNumber.Value = ""
Me.txtOrderDate.Value = ""
Me.txtOrderStatus.SetFocus
End Sub


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default No Duplicates Allowed


I would have to know the error in order to have a thought..
Also, are you sure that the Msgbox line is the bad line?
In any case, I would try Dave's solution first.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"D"
wrote in message

Thank You very much. Place your code into my sheet and I am having one
problem:

It doesn't like the "MsgBox "found in row " & vStatus" portion.

Any thoughts?

(By the way, you are going to make me look like a hero!!!)



  #6   Report Post  
Posted to microsoft.public.excel.programming
D D is offline
external usenet poster
 
Posts: 121
Default No Duplicates Allowed

Thank you for your help. I did get the code to work. Seems there was some
issue with the spaces in the the front of the line and gave me a syntax
error.

Thanks Again!!

"Jim Cone" wrote:


I would have to know the error in order to have a thought..
Also, are you sure that the Msgbox line is the bad line?
In any case, I would try Dave's solution first.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"D"
wrote in message

Thank You very much. Place your code into my sheet and I am having one
problem:

It doesn't like the "MsgBox "found in row " & vStatus" portion.

Any thoughts?

(By the way, you are going to make me look like a hero!!!)


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
allowed/taken Martha Excel Worksheet Functions 1 July 12th 07 04:07 PM
allowed / taken Martha Excel Worksheet Functions 3 July 11th 07 07:56 PM
MODIFICATION IS NOT ALLOWED lisasbulldogs Excel Worksheet Functions 1 May 31st 06 06:27 PM
parameters not allowed begrry Excel Discussion (Misc queries) 0 May 3rd 05 03:56 PM
Are the macros allowed? Milan[_2_] Excel Programming 5 June 29th 04 04:09 PM


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