August 11, 2010

Switch case in excel micro

If you want to use switch case in Excel micro then you can see following example. Its mentioned clearly how to use switch  as per value of cell.

 Sub configs(ByVal Target As Range)  
 Dim Indexof As Integer  
 Dim strT As String  
 Indexof = InStrRev(Target.Address, "$")  
 strT = Mid(Target.Address, 1, Indexof)  
 Select Case strT  
 Case "$D$"  
 Call drange(Target) 'drange --> generate Crop Id [D],Crop Variety DropDown [E] from Crop Name [C]  
 Case "$E$"  
 Call erange(Target) 'erange --> generate Crop Variety Id [F] from Crop Variety Name [E]  
 Case "$K$"  
 Call krange(Target) 'krange --> generate District Id [L] ,Taluka DropDown [M] from District Name [K]  
 Case "$M$"  
 Call mrange(Target) 'mrange --> generate Taluka Id [N], Village DropDown [O] from Taluka Name [M]  
 Case "$O$"  
 Call orange(Target) 'orange --> generate Village Id [P] from Village Name [O]  
 End Select  
 End Sub