iT邦幫忙

0

如何用If/then/else function and for loop to solve it?

Create a sub procedure, named “Task1” to change the font color of “Fruits” to Blue and the font color of the other categories to Magenta color using If/Then/Else structure.
https://ithelp.ithome.com.tw/upload/images/20200321/201257538BYhYHAwcL.png (尼個係原本嘅畫面)

以下係我打嘅但係我完全唔知自己錯咗邊個位
Dim i As Integer
Dim RowCount As Integer
Dim Msg As Variant
Dim Title As String
Dim category As String
Dim cell As Range

With Sheets("Sheet1").Range("a1")

    ' Another way to count the number of rows needed
    RowCount = Cells(Rows.Count, 1).End(xlUp).Row
    
   
 
    For i = 2 To RowCount
        ' insert the IF/THEN/ELSE structure here to
        ' format the font color of Fruits to blue,
        ' and the rest of the others to magenta
    
    
    
    If ActiveCell.Value = "Fruits" Then
    ActiveCell.Resize(1, 3).Font.Color = vbBlue
    Else
    ActiveCell.Resize(1, 3).Font.Color = vbMagenta
    End If
    
    Next
End With

尚未有邦友回答

立即登入回答