Skip to content
The Chat Archive
gpt-3.5-turbo-0301· OpenAI WildChat-4.8M (AI2)

这个vba的语法错误在哪 If sourceSheet.Cells(i, 50).Value = "" Then: kehu = sourceSheet.Cells(i,…

  1. User

    这个vba的语法错误在哪 If sourceSheet.Cells(i, 50).Value = "" Then: kehu = sourceSheet.Cells(i, 40).Value Else: kehu = sourceSheet.Cells(i, 50).Value

  2. Assistant

    应该把冒号(:)改成换行。正确代码如下:

    If sourceSheet.Cells(i, 50).Value = "" Then kehu = sourceSheet.Cells(i, 40).Value Else kehu = sourceSheet.Cells(i, 50).Value End If

  3. User

    vba elif怎么写

  4. Assistant

    在VBA中没有elif关键词,但可以使用嵌套的if语句来实现类似的功能。例如:

    If condition1 Then
        ' 执行语句1
    ElseIf condition2 Then
        ' 执行语句2
    ElseIf condition3 Then
        ' 执行语句3
    Else
        ' 执行语句4
    End If
    

    当condition1为真时,执行语句1;当condition1为假且condition2为真时,执行语句2;当condition1和condition2都为假且condition3为真时,执行语句3;否则执行语句4。注意,ElseIf后面也要跟上Then。