How can I write this ElseIf as a Case statement in Excel-VBA?

SteelyDanFan

Formats each cell in the plotting area according to text in cell, but would like to know how to do the same with a Case statment.

For Each Cell In Range("B11:AB200")
    If Cell.Value = ""
        Cell.Interior.Color = RGB(230, 230, 230) Then
    ElseIf Cell.Value = "tp" Then
        Cell.Interior.Color = RGB(0, 51, 150)
        Cell.Font.Color = RGB(170, 170, 170)
        Cell.Font.FontStyle = "Normal"
    ElseIf Cell.Value = "ot" Then
        Cell.Interior.Color = RGB(200, 0, 0)
        Cell.Font.Color = RGB(170, 170, 170)
        Cell.Font.FontStyle = "Normal"
    ElseIf Cell.Value = "lu" Then
        Cell.Interior.Color = RGB(180, 180, 50)
        Cell.Font.Color = RGB(120, 120, 120)
        Cell.Font.FontStyle = "Normal"
    Else
        Cell.Interior.Color = RGB(255, 255, 0)
        Cell.Font.Color = RGB(120, 120, 120)
        Cell.Font.FontStyle = "Normal"
    End If
Next Cell

I have tried the following but get a 'type mistmacth'

For Each Cell In Range("B11:AB200")
Select Case Range("B11:AB200")
    Case Cell.Value = ""
        Cell.Interior.Color = RGB(230, 230, 230)
    Case Cell.Value = "tp"
        Cell.Interior.Color = RGB(0, 51, 150)
        Cell.Font.Color = RGB(170, 170, 170)
        Cell.Font.FontStyle = "Normal"
    Case Cell.Value = "ot"
        Cell.Interior.Color = RGB(200, 0, 0)
        Cell.Font.Color = RGB(170, 170, 170)
        Cell.Font.FontStyle = "Normal"
    Case Cell.Value = "lu"
        Cell.Interior.Color = RGB(180, 180, 50)
        Cell.Font.Color = RGB(120, 120, 120)
        Cell.Font.FontStyle = "Normal"
    Case Else
        Cell.Interior.Color = RGB(255, 255, 0)
        Cell.Font.Color = RGB(120, 120, 120)
        Cell.Font.FontStyle = "Normal"
End Select
Next Cell
Arthur Samarcos

Just a few tweaks.

    For Each Cell In Range("B11:AB200")
Select Case Cell.value
    Case ""
        Cell.Interior.Color = RGB(230, 230, 230)
    Case "tp"
        Cell.Interior.Color = RGB(0, 51, 150)
        Cell.Font.Color = RGB(170, 170, 170)
        Cell.Font.FontStyle = "Normal"
    Case "ot"
        Cell.Interior.Color = RGB(200, 0, 0)
        Cell.Font.Color = RGB(170, 170, 170)
        Cell.Font.FontStyle = "Normal"
    Case "lu"
        Cell.Interior.Color = RGB(180, 180, 50)
        Cell.Font.Color = RGB(120, 120, 120)
        Cell.Font.FontStyle = "Normal"
    Case Else
        Cell.Interior.Color = RGB(255, 255, 0)
        Cell.Font.Color = RGB(120, 120, 120)
        Cell.Font.FontStyle = "Normal"
End Select
Next Cell

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to Write OR statement in excel VBA with multiple conditions

From Dev

How can I write an empty case in Swift?

From Dev

Oracle SQL - How can I write an insert statement that is conditional and looped?

From Dev

How can I sort on the results of a case statement in Spring Data?

From Dev

how to write case statement in mysql?

From Dev

how can i use case statement after using left join?

From Dev

How can I make my switch statement case insensitive?

From Dev

How can I write SQL in Oracle in my case?

From Dev

VBA/Excel If...Then...ElseIf...Else Statement copy down column issue

From Dev

How can I write this as a switch statement?

From Dev

how can I write a test case to compare infinity value?

From Dev

How can I correct this query that involves a CASE statement for a summary?

From Dev

How can I convert this IF statement to use in VBA

From Dev

How to write a VBA multi row coresponding cells If Statement in Excel

From Dev

how to write the select statement in case statement

From Dev

Excel 2010 formula, How do I write this formula? (VBA)

From Dev

How can I use a case statement with a Drop Box? Access Database

From Dev

How can i loop through These with A CASE statement?

From Dev

how to write case statement in mysql?

From Dev

How can i shorten this PHP code? (if - elseif)

From Dev

how can i use case statement after using left join?

From Dev

How can I use conditional constructs in a bash case statement?

From Dev

ElseIf with Dim Not Working (Excel VBA)

From Dev

Vba Excel Can I change to upper case using With function?

From Dev

If Then ElseIF Statement in Excel VBA

From Dev

How can i write a variabile in the Function Console.Write in this case?

From Dev

How i can use if/else/elseif statment in my case - PHP

From Dev

Excel VBA If ElseIF else

From Dev

if_elseif statement in VBA

Related Related

  1. 1

    How to Write OR statement in excel VBA with multiple conditions

  2. 2

    How can I write an empty case in Swift?

  3. 3

    Oracle SQL - How can I write an insert statement that is conditional and looped?

  4. 4

    How can I sort on the results of a case statement in Spring Data?

  5. 5

    how to write case statement in mysql?

  6. 6

    how can i use case statement after using left join?

  7. 7

    How can I make my switch statement case insensitive?

  8. 8

    How can I write SQL in Oracle in my case?

  9. 9

    VBA/Excel If...Then...ElseIf...Else Statement copy down column issue

  10. 10

    How can I write this as a switch statement?

  11. 11

    how can I write a test case to compare infinity value?

  12. 12

    How can I correct this query that involves a CASE statement for a summary?

  13. 13

    How can I convert this IF statement to use in VBA

  14. 14

    How to write a VBA multi row coresponding cells If Statement in Excel

  15. 15

    how to write the select statement in case statement

  16. 16

    Excel 2010 formula, How do I write this formula? (VBA)

  17. 17

    How can I use a case statement with a Drop Box? Access Database

  18. 18

    How can i loop through These with A CASE statement?

  19. 19

    how to write case statement in mysql?

  20. 20

    How can i shorten this PHP code? (if - elseif)

  21. 21

    how can i use case statement after using left join?

  22. 22

    How can I use conditional constructs in a bash case statement?

  23. 23

    ElseIf with Dim Not Working (Excel VBA)

  24. 24

    Vba Excel Can I change to upper case using With function?

  25. 25

    If Then ElseIF Statement in Excel VBA

  26. 26

    How can i write a variabile in the Function Console.Write in this case?

  27. 27

    How i can use if/else/elseif statment in my case - PHP

  28. 28

    Excel VBA If ElseIF else

  29. 29

    if_elseif statement in VBA

HotTag

Archive