16 Select Case en VBA Excel
Sub AsignarComisionMarketingPro() Dim canal As String Dim comision As Double Dim inversion As Double Dim fila As Integer ' 1. Identificamos la fila activa fila = ActiveCell.Row ' 2. Capturamos el canal y lo convertimos a MAYÚSCULAS para evitar errores canal = UCase(Trim(Cells(fila, 1).Value)) inversion = Cells(fila, 2).Value ' 3. Estructura Select Case con múltiples opciones por caso Select Case canal Case "FACEBOOK", "INSTAGRAM" comision = 0.15 Case "GOOGLE ADS" comision = 0.12 Case "LINKEDIN" comision = 0.2 Case "" MsgBox "La celda del canal está vacía.", vbExclamation Exit Sub Case Else ' Para canales nuevos o no listados (ej. TikTok) comision = 0.1 End Select ' 4. Escribimos los resultados en la tabla Cells(fila, 3).Value = comision Cells(fila, 3).NumberFormat = "0%" ' Formato porcentaje Cells(fila, 4).Value = inversion * comision Cells(fila, 4).NumberFormat = "$#,##0.00" ' Formato moneda ' Mensaje de confirmación en barra de estado (menos intrusivo que MsgBox) Application.StatusBar = "Comisión asignada para " & canal End Sub
Download
0 formatsNo download links available.