473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Using If Function in VBA for different conditions and Different criteria

I have some data which has three values: Pass/Rejected/On Hold, Now I want to save only pass data in Different sheet,
but there is one condition, If There is no pass data, It shows msgbox "there is no Pass data", If only one Pass data found, it would save in 'sheet 2' and if more than one Pass Data found, it would save in 'sheet 2'.
Please help me in these.
I have tried these, it's works, codes are correct for 'pass_more_than_one' and 'pass_only_one', I think some thing wrong with If function only, so please suggest.

Expand|Select|Wrap|Line Numbers
  1. Sub TICKLER_AR()
  2.  
  3. Dim r As Range 
  4. Dim j As Integer
  5.  
  6. Application.ScreenUpdating = False
  7. Application.DisplayAlerts = False
  8.  
  9. 'Tickler Working
  10. Set r = Range(Range("A6"), Range("AF6").End(xlDown))
  11. Sheets("Settlement").Range("5:5").AutoFilter
  12. Range("AF1").Select
  13. ActiveSheet.Range("A:AM").AutoFilter Field:=32, Criteria1:="Pass Waiver"
  14.  
  15. On Error Resume Next ' If the lookup fails, ignore the error
  16.     ' the following assumes Part is in Column A
  17.     j = WorksheetFunction.CountA(r.Cells.SpecialCells(xlCellTypeVisible))
  18. On Error GoTo 0 ' Resume normal error handling
  19.  
  20. If j = 0 Then
  21. MsgBox "There is no Pass Waiver Data..!"
  22.  
  23. ElseIf j <> 1 Then
  24. Call pass_only_one
  25.  
  26. Else
  27. Call pass_more_than_one
  28. End If
  29.  
  30. Application.ScreenUpdating = True
  31. Application.DisplayAlerts = True
  32. End Sub
Sep 4 '15 #1
1 2139
Luuk
1,047 Expert 1GB
Looking at line #23 it seems to me, if I understand what your problem is that this should be:
Expand|Select|Wrap|Line Numbers
  1. else if j=1 then
But maybe you should alo look for the CASE statement
(http://www.techonthenet.com/excel/formulas/case.php)
Sep 5 '15 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Lenard Lindstrom | last post by:
I was wondering if anyone has suggested having Python determine a method's kind from its first parameter. 'self' is a de facto reserved word; 'cls' is a good indicator of a class method ( __new__...
1
by: pvdm | last post by:
Hi, I am writing an app which encapsulates a multimedia timer. I implemented a TimerProc as static member function and a static member variable pThis as pseudo this variable to access in the...
16
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for info about ]
14
by: jagadeeshbp | last post by:
Hi, I am having a CPP file which defines a class: class xyz{ public: int (*funcptr)(void); } A function foo is defined in a "C file"
0
by: Reggie | last post by:
Hi and TIA, I Have a query that uses a function for setting the Criteria. When I view the return value of the finction it appears to be exactly what I want for my criteria. The problem is if I...
3
by: I_was_here | last post by:
Hey if anyone is a query pro please showoff some knowledge thx. Ie: I have a table with : part price location qty 1 part repeats throughout the table and its price remains the same but it...
5
by: Nico | last post by:
My database have 20 tables and many users. I wish to store encrypted data in 3 tables and have only 3 users have access to them, walking into tables or using forms. Can someone point me a direct...
22
by: Daniel Rucareanu | last post by:
I have the following script: function Test(){} Test.F = function(){} Test.F.FF = function(){} Test.F.FF.FFF = function(){} Test.F.FF.FFF.FFFF = function(){} //var alias = function(){}; var...
3
by: pradeep | last post by:
Hello, Can any one tell me different functions or properties of javascript which are gives different outputs on different browsers ? Thanks in advance. Bye
7
by: Nash | last post by:
Hi, I have two different files which is filled with data from two different structures like struct student { char* name; int age; };
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.