【发布时间】:2018-09-24 10:44:58
【问题描述】:
我不是程序员,但我试图在 VBA Excel 中自动化我的日常工作。
我在 VBA 中为我的表格一行写了“If else”代码,它可以工作。但在我的表中有 20 行。而且我需要在每一行工作“如果其他”条件。变量必须更改数据,执行条件并转到另一行等。
我想象代码的逻辑,假设我需要 LOOP 来表示范围。但我不明白循环的语法。
在我的代码下面。
变量:文本、score1、score2、score3 - 必须在每一行中更改单元格。执行后转到他下面的下一行。
If Else 条件必须在每一行(范围内)都有效。执行后转到他下面的下一行。
结果 - 在“过去的值”之后转到他下面的下一行,然后再过去新行的下一个 If Else 条件的另一个值。
请帮我解决这个问题。
Sub Test()
Dim score1 As Double, score2 As Double, score3 As Double, result As String, text As String
text = Range("G3").Value
score1 = Range("C3").Value
score2 = Range("D3").Value
score3 = Range("E3").Value
name1 = "Company A"
name2 = "Company B"
currenc = "Dollars"
If score1 = 0 And score2 = 0 Then
result = text + " " + name1 + " didn't count and " + name2 + " didn't count."
ElseIf score1 = score2 Then
result = text + " " + name1 + " some code..............."
ElseIf score1 > score2 And score2 <> 0 Then
result = text + " " + name1 + " some code..............."
ElseIf score1 < score2 And score1 <> 0 Then
result = text + " " + name1 + " some code..............."
Else
result = text + " 00000000"
End If
Range("I3").Value = result
End Sub
【问题讨论】: