vba help - replace if with select case

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

How to use select case for below situation. my code gives correct output,
want to replace the code with select case.

VBA Code:
Sub test()

    Dim i As Long
    
    For i = 2 To 10
        
        If Cells(i, 1).Value >= 0 Then
            Cells(i, 2).Value = "Overdue"
        ElseIf Cells(i, 1).Value < 0 Then
            Cells(i, 2).Value = "current"
        Else
            
        End If
   
    Next i


End Sub

Column A is a input Column, Column B needs to fill. expected output is in Column E.

Book27
ABCDE
1AgeingStatusAgeingExpected status
2-10-10current
300Overdue
45050Overdue
5-7-7current
Sheet1


Thanks
mg
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Just converting your IF to a SELECT gives:
VBA Code:
Sub test()

    Dim i As Long
    
    For i = 2 To 10
        Select Case Cells(i, 1).Value
            Case Is >= 0
                Cells(i, 2).Value = "Overdue"
            Case Is < 0
                Cells(i, 2).Value = "current"
            Case Else
                ' Will never get here
        End Select
   
    Next i


End Sub
 
Upvote 0
Hi CephasOZ,

Thanks for your help, it worked.


Thanks
mg
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,207
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top