Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于无效限定符上的Excel VBA的问题_Excel_Vba - Fatal编程技术网

关于无效限定符上的Excel VBA的问题

关于无效限定符上的Excel VBA的问题,excel,vba,Excel,Vba,我目前正在做vba作业…但我被困在这件事里了。它说有无效的限定符,无法运行。请帮忙,非常感谢 Dim i As Integer Dim RowCount As Integer Dim category As String Dim product As String Dim quantity As String With Sheets("Sheet1") RowCount = Cells(Rows.Count, 1).End(xlUp).Row ' Another way to

我目前正在做vba作业…但我被困在这件事里了。它说有无效的限定符,无法运行。请帮忙,非常感谢

Dim i As Integer
Dim RowCount As Integer
Dim category As String
Dim product As String
Dim quantity As String

With Sheets("Sheet1")
    RowCount = Cells(Rows.Count, 1).End(xlUp).Row

    ' Another way to count the number of rows needed

    Range("A1").Select
    category = ActiveCell.Offset(i, 0).Value
    product = ActiveCell.Offset(i, 1).Value
    quantity = ActiveCell.Offset(i, 2).Value

    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 category = "Fruits" Then
    category.Font.Color = vbBlue
    product.Font.Color = vbBlue
    quantity.Font.Color = vbBlue

    Else
    category.Font.Color = vbMagenta
    product.Font.Color = vbMagenta
    quantity.Font.Color = vbMagenta
    End If
    Next

End With

使用范围和长度。将集合移动到循环中

Dim i As Long
Dim RowCount As Long
Dim category As Range
Dim product As Range
Dim quantity As Range

With Sheets("Sheet1")
    RowCount = .Cells(.Rows.Count, 1).End(xlUp).Row

    ' Another way to count the number of rows needed

    For i = 2 To RowCount
    Set category = .Cells(i, 1)
    Set product = .Cells(i, 2)
    Set quantity = .Cells(i, 3)
        ' 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 category = "Fruits" Then
            category.Font.Color = vbBlue
            product.Font.Color = vbBlue
            quantity.Font.Color = vbBlue
        Else
            category.Font.Color = vbMagenta
            product.Font.Color = vbMagenta
            quantity.Font.Color = vbMagenta
        End If
    Next

End With
或跳过变量:

With Sheets("Sheet1")
    Dim RowCount As Long
    RowCount = .Cells(.Rows.Count, 1).End(xlUp).Row

    Dim i As Long
    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 .Cells(i, 1) = "Fruits" Then
            .Range(.Cells(i, 1), .Cells(i, 3)).Font.Color = vbBlue
        Else
            .Range(.Cells(i, 1), .Cells(i, 3)).Font.Color = vbMagenta
        End If
    Next

End With

类别是一个字符串而不是一个范围,因此不能使用
字体。颜色
作为旁白,
行数
正在使用活动的工作表而不是
工作表(“工作表1”)
您需要在
单元格
之前放置一个
,ohh最终在这里看到它。非常感谢你,快跑和热身。你们是救生员!!Thx斯科特!!你救了我的命!!!但我也真的很想知道我的密码有什么问题,我在评论中告诉过你。字符串没有
Font.Color
。它们是没有格式的内存变量。那是你的错误。