Why Select Case doesn't work in this code VBA?

J_RMCF

New Member
Joined
Jun 22, 2019
Messages
6
I have to calculate "Costo" (Cost) by Select Case, but whe I run the macro it just put 0 in Cost not the numbers I put in the macro. Something is missing and I don't know what. Cost (P5-P50) Tipo de Pase (O5-O50)



Sub Ejercicio1()


Dim Estacionamiento As String
Dim Casillero As String
Dim TipoDePase As String
Dim Costo As Double
Dim contador As Double


contador = 5
Range("P5").Select


Do While contador <= 50


Select Case TipoDePase
Case "Normal":
Costo = 95200
Case "Lounge":
Costo = 280000
Case "Lounge Premium":
Costo = 392000

End Select


ActiveCell.Offset(1, 0).Select
contador = contador + 1


Loop




End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try this. It assigns the r variable to your range in 'O5:50'. Then it loops through each cell, uses the 'Select Case' to assign a value to 'Costo', then puts that value in column 'P'.

Code:
Sub Ejercicio1()
Dim Estacionamiento As String
Dim Casillero As String
Dim TipoDePase As String
Dim Costo As Double
Dim contador As Double

Dim r As Range, cel As Range

Set r = Range("O5:O50")

For Each cel In r
    Select Case cel.Value
        Case "Normal":
            Costo = 95200
        Case "Lounge":
            Costo = 280000
        Case "Lounge Premium":
            Costo = 392000
    End Select
    
    cel.Offset(, -1).Value = Costo
Next cel

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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