gpt4 book ai didi

vba - 为什么单元格(变量 ,"B")不起作用

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

我创建了一个小程序,我真的不明白为什么我的代码不能工作:O

For Each numberItem In Worksheets("Sheet1").Range("A01:A240").Cells
Dim c As String
Dim cpt As Long
cpt = numberItem
c = Cells(cpt, "B") !!!!!ERROR !!!!!

如果我输入 1 而不是 cpt,它就可以工作。
我在网上没有找到好的东西。
是否存在简单的东西?

多谢你们

最佳答案

相信你只需要指定你想要的行:

For Each numberItem In Worksheets("Feuil1").Range("A01:A240").Cells
Dim c As String
Dim cpt As Long
cpt = numberItem.Row
c = Cells(cpt, "B")
Next

根据@omegastripes 评论更新:

假设循环位于单元格 A10 并且 A10 的值为 37

选项 1:您想使用 numberItem 中的行号:
For Each numberItem In Worksheets("Feuil1").Range("A01:A240").Cells
Dim c As String
Dim cpt As Long
cpt = numberItem.Row
c = Cells(cpt, "B")
Next

结果: c = Cells(10, "B")
选项 2:您想使用单元格 A10 中的值,然后稍作调整
For Each numberItem In Worksheets("Feuil1").Range("A01:A240").Cells
Dim c As String
Dim cpt As Long
cpt = numberItem.Value
c = Cells(cpt, "B")
Next

结果: c = Cells(37, "B")

关于vba - 为什么单元格(变量 ,"B")不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36516668/

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