Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - Countif problem

Dim x As Long, y As Long, z As Long, searchstring As String
If ActiveCell = "" Then Exit Sub
searchstring = "DS45"
x = Range("I65536").End(xlUp).Row
y = Application.WorksheetFunction.CountIf(Range("I:I") , searchstring)
If y 3 Then
MsgBox "This Customer has reached their limit. Only 3 DVD's allowe
per customer!" & vbCrLf & vbCrLf & "Mark Smith - Manager"
vbInformation + vbOKOnly, "Disc Emporium - DVD Limit Check"
ActiveCell = ""
ActiveCell.Offset(, 5) = "On shelf"

I have the above formula which checks the search string for a value o
more than 3 entries, then brings up a message box...But, this work
fine, however, I have other strings that also needed to be checked..Ho
can I get the code to check more than one besides the "DS45"...I hav
20 or so more numbers in my datebase that I would like to check fo
greater than 3...Any help would be great

Thanks
Mar

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - Countif problem

thanks for quick reply...But not quite sure where to add that bit o
code :( Not the best using VB..Just been putting snippits togethe
really...

Mar

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Excel VBA - Countif problem

Dim x As Long, y As Long, z As Long, searchstring As String
Dim varr(1 to 3), msg1(1 to 3), msg2(1 to 3)
varr(1) = "DS45"
varr(2) = "AB11"
varr(3) = "RB"
msg = "This Customer has reached their limit. " & _
"Only 3 DVD's allowed per customer!"
msg1(1) = "Mark Smith - Manager"
msg1(2) = "Jimbo Hunt - Employee"
msg1(3) = "Mortimer Snerd - Musician"
msg2(1) = "Disc Emporium - DVD Limit Check"
msg2(2) = "Dicks Glock Shop"
msg2(3) = "Inconsequential Tunes"
If ActiveCell = "" Then Exit Sub
for i = 1 to 3
searchstring = varr(i)
x = Range("I65536").End(xlUp).Row
y = Application.WorksheetFunction.CountIf(Range("I:I") , searchstring)
If y 3 Then
MsgBox msg & vbCrLf & vbCrLf & msg1(i),
vbInformation + vbOKOnly, msg2(i)
ActiveCell = ""
ActiveCell.Offset(, 5) = "On shelf"
End If
Loop

or if your values are in cells

Dim x As Long, y As Long, z As Long, searchstring As String
for each cell in Worksheets("List").Range("A1:A20")
searchstring = cell.Value
y = Application.WorksheetFunction.CountIf(Range("I:I") , searchstring)
If y 3 Then
MsgBox cell.Value & " has reached their limit. Only 3 DVD's allowed
per customer!" & vbCrLf & vbCrLf & "Mark Smith - Manager",
vbInformation + vbOKOnly, "Disc Emporium - DVD Limit Check"
Cell = ""
Cell.Offset(, 5) = "On shelf"
End if
Next

--
Regards,
Tom Ogilvy





"Mark1ace1 " wrote in message
...
Dim x As Long, y As Long, z As Long, searchstring As String
If ActiveCell = "" Then Exit Sub
searchstring = "DS45"
x = Range("I65536").End(xlUp).Row
y = Application.WorksheetFunction.CountIf(Range("I:I") , searchstring)
If y 3 Then
MsgBox "This Customer has reached their limit. Only 3 DVD's allowed
per customer!" & vbCrLf & vbCrLf & "Mark Smith - Manager",
vbInformation + vbOKOnly, "Disc Emporium - DVD Limit Check"
ActiveCell = ""
ActiveCell.Offset(, 5) = "On shelf"

I have the above formula which checks the search string for a value of
more than 3 entries, then brings up a message box...But, this works
fine, however, I have other strings that also needed to be checked..How
can I get the code to check more than one besides the "DS45"...I have
20 or so more numbers in my datebase that I would like to check for
greater than 3...Any help would be great

Thanks
Mark


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - Countif problem

It is the second code I want..I have tried it but it only allow
customers to have one and message box does not kill itself afte
clicking ok...

Mark

Thanks for the help ....:

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Excel VBA - Countif problem

I didn't alter your logic. I suspect your msgbox is being regenerated by
the next cell checked.

I doubt the code reflects what your business rules are. You probably need
to state in explicit terms what type of test you are trying to perform -
what the rules are.

--
Regards,
Tom Ogilvy

"Mark1ace1 " wrote in message
...
It is the second code I want..I have tried it but it only allows
customers to have one and message box does not kill itself after
clicking ok...

Mark

Thanks for the help ....:)


---
Message posted from http://www.ExcelForum.com/



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
Problem with COUNTIF Cheryl MM[_2_] Excel Discussion (Misc queries) 4 January 2nd 08 04:15 PM
Problem w countif ingeman Excel Discussion (Misc queries) 2 July 17th 06 08:05 AM
COUNTIF problem with NOW() Spreadsheet Excel Worksheet Functions 21 June 26th 06 09:47 PM
Countif Problem John Moore Excel Discussion (Misc queries) 5 November 27th 05 07:09 PM
countif(and) problem Len Dolby Excel Programming 3 October 24th 03 01:48 PM


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

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

About Us

"It's about Microsoft Excel"