gpt4 book ai didi

string - VBA 范围和字符串混淆

转载 作者:行者123 更新时间:2023-12-03 02:36:57 26 4
gpt4 key购买 nike

我认为我对范围和字符串之间的差异有疑问。尝试让它在范围内的单元格中搜索任何获胜者,然后吐出一个分值。

Sub it()
Dim Round1 As Range
Dim Round2 As Range
Dim lngCnt As Long
Dim Winner() As String
Dim pointSum As Double
ReDim Winner(1 To 4)
Winner(1) = "Mohler"
Winner(2) = "Scotter"
Winner(3) = "DKGAY"
Winner(4) = "Lassie"
Set Round1 = Range("L3,L11,L22,L32").Text
For Each Winner In Round1
lngCnt = lngCnt + 10
Winner(lngCnt) = pointSum.Value
Next
MsgBox pointSum.Value
End Sub

最佳答案

您将需要两个循环:

Sub it()
Dim Round1 As Range
Dim Round2 As Range
Dim lngCnt As Long
Dim Winner() As String
Dim pointSum As Double
Dim rng As Range
Dim i As Long
ReDim Winner(1 To 4)
Winner(1) = "Mohler"
Winner(2) = "Scotter"
Winner(3) = "DKGAY"
Winner(4) = "Lassie"
Set Round1 = Range("L3,L11,L22,L32")
For Each rng In Round1
For i = 1 To UBound(Winner)
If rng.Value = Winner(i) Then
pointSum = pointSum + 10
Exit For
End If
Next i
Next rng

MsgBox pointSum.Value
End Sub

第一个循环遍历范围,第二个遍历字符串数组。当它找到相等的位置时,它会加 10。

关于string - VBA 范围和字符串混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36727671/

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