Hi Anish,
100 is just a label. In this case, it removes the need to add an 'Else' to each 
'If Then' since if the 'If' statement is true, then the code jumps to the 100 
label. If the statement is false, it just progresses to the next 'If' 
statement. This way we save 156 'End If's
Dave.

Date: Mon, 26 Oct 2009 14:27:12 +0530
Subject: $$Excel-Macros$$ Re: Need Urgent Help (While Statement)
From: anish....@gmail.com
To: excel-macros@googlegroups.com

Thanks Dave,
 
Looks like we have got another idea to ignore count of ENDIF's ;) ... by the 
way wht r disadvantages of using 100 instead of ENDIF??
 
Cheers!!
ANISH


On Mon, Oct 26, 2009 at 2:23 PM, Dave Bonallack <davebonall...@hotmail.com> 
wrote:


Hi Anish,
I also think it's just a mis-count on the End If's
You can simplify your code like this. 


Sub dept()
    i = 1
    z = Cells(Rows.Count, "B").End(xlUp).Row
    While i <= z
        If Cells(i, 2).Value Like "*FINANCE*" Then Cells(i, 4) = "FINANCE / 
ACCOUNTING": GoTo 100

        If Cells(i, 2).Value Like "*ACCOUNTS*" Then Cells(i, 4) = "FINANACE / 
ACCOUNTING": GoTo 100
        If Cells(i, 2).Value Like "*SALES*" Then Cells(i, 4) = "SALES": GoTo 100

        '(IN BETWEEN THR R MORE THAN 100 IF CONDITIONS LIKE THIS)
100
    i = i + 1
    Wend
End Sub

Some programmers disapprove of using GoTo, but for your code it removes the 
need for End If's.


Regards - Dave.




Date: Mon, 26 Oct 2009 10:47:27 +0530
Subject: $$Excel-Macros$$ Need Urgent Help (While Statement)
From: anish....@gmail.com
To: excel-macros@googlegroups.com 



Hello Experts..
 
I m using While and Wend statement in my code and it has got more than 100 if 
conditions. when I run the macro it says "WEND WITHOUT WHILE", it's buggin my 
head...and I don know wht's wrong. Could anyone of you please help me... 

 
Sample code...
 
Sub dept()
i = 1
z = Cells(Rows.Count, "B").End(xlUp).Row
While i <= z
If Cells(i, 2).Value Like "*FINANCE*" Then
Cells(i, 4) = "FINANCE / ACCOUNTING"
Else
If Cells(i, 2).Value Like "*ACCOUNTS*" Then

Cells(i, 4) = "FINANACE / ACCOUNTING"
Else
If Cells(i, 2).Value Like "*SALES*" Then
Cells(i, 4) = "SALES"
(IN BETWEEN THR R MORE THAN 100 IF CONDITIONS LIKE THIS)
endif
endif
endif
i=i+1
wend
end sub
 
-best
ANISH






Find out how here Use Messenger in your Hotmail inbox











                                          
_________________________________________________________________
Need a place to rent, buy or share? Let us find your next place for you!
http://clk.atdmt.com/NMN/go/157631292/direct/01/
--~--~---------~--~----~------------~-------~--~----~
----------------------------------------------------------------------------------
Some important links for excel users:
1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at 
http://www.excelitems.com
2. Excel tutorials at http://www.excel-macros.blogspot.com
3. Learn VBA Macros at http://www.vbamacros.blogspot.com
4. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 

To post to this group, send email to excel-macros@googlegroups.com
If you find any spam message in the group, please send an email to:
Ayush Jain  @ jainayus...@gmail.com or
Ashish Jain @ 26may.1...@gmail.com
<><><><><><><><><><><><><><><><><><><><><><>
HELP US GROW !!

We reach over 6,500 subscribers worldwide and receive many nice notes about the 
learning and support from the group. Our goal is to have 10,000 subscribers by 
the end of 2009. Let friends and co-workers know they can subscribe to group at 
http://groups.google.com/group/excel-macros/subscribe
-~----------~----~----~----~------~----~------~--~---

Reply via email to