gpt4 book ai didi

vba - CountIf 返回 0 值

转载 作者:行者123 更新时间:2023-12-04 21:55:47 25 4
gpt4 key购买 nike

我想在“旧值”标题下查找值为“橙色”的列中的单元格数。
但是我得到的值为 0,尽管我在单元格中有值。请帮助使用以下代码。

Private Sub CommandButton1_Click()

Dim x As Workbook

Dim Wks As Worksheet

Dim aCell As Range

Dim col As Long

Dim Var1

Dim i As Integer

Dim a

Set x = Workbooks.Open("C:\*********\file.xls")

Set Wks = x.Worksheets("file")

Set aCell = Wks.Range("A1:X1000").Find(What:="Old Value", LookIn:=xlValues, LookAt:=xlWhole, _
MatchCase:=False, SearchFormat:=False)
col = aCell.Column

For i = 1 To 1000
Var1 = Application.WorksheetFunction.CountIf(Wks.Cells(i, col), "*orange*")

Next i
MsgBox Var1


End Sub

最佳答案

For这里不需要循环。代替

For i = 1 To 1000
Var1 = Application.WorksheetFunction.CountIf(Wks.Cells(i, col), "*orange*")
Next i

尝试
Var1 = Application.WorksheetFunction.CountIf(Wks.Columns(col), "*orange*")

关于vba - CountIf 返回 0 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45161632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com