473,386 Members | 1,736 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,386 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 2136
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.