Select Case sub mismatch

keeper85

New Member
Joined
Jun 10, 2011
Messages
15
I am looking at column 9 ("I") and 16 ("P"). I went to add +1 to the value in column P in case I have either "OGBL", "OGBM" or "OGBL" in the corresponding row in column P. Otherwise I want to keep everything intact. Please note that some values in column I are "#N/A". I wrote the following loop for this, however, it gives me error. Any suggestions regarding this would be appreciated:

HTML:
Sub hey()
 
Dim LastRow As Integer
With Workbooks(ReportBook).Sheets(ReportSheet)
    LastRow = .Range("g65536").End(xlUp).Row
 
    On Error Resume Next
 
    For n = 2 To LastRow
 
    ticker = Workbooks(ReportBook).Sheets(ReportSheet).Cells(n, 9)
 
 
        Select Case ticker
            Case ticker = "OGBS"
                .Cells(n, 16).Value = .Cells(n, 16).Value + 1
            Case ticker = "OGBM"
                .Cells(n, 16).Value = .Cells(n, 16).Value + 1
            Case ticker = "OGBL"
                .Cells(n, 16).Value = .Cells(n, 16).Value + 1
        End Select
'
    Next n
End With
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
This will protect your routine against cells with error values.
Code:
Sub hey()
 
Dim LastRow As Integer
Dim ticker as String
With Workbooks(ReportBook).Sheets(ReportSheet)
    LastRow = .Range("g65536").End(xlUp).Row
 
    For n = 2 To LastRow
 
        ticker = CStr(.Cells(n, 9).Value)
 
        Select Case UCase(ticker)
            Case "OGBS", "OGBM", "OGBL"
                .Cells(n, 16).Value = Val(Cstr(.Cells(n, 16).Value)) + 1
        End Select

    Next n
End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,693
Members
452,938
Latest member
babeneker

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