gpt4 book ai didi

excel - 如何在 VBA 中将一长行代码分成多行

转载 作者:行者123 更新时间:2023-12-04 19:49:39 24 4
gpt4 key购买 nike

我有很长的代码,我想分成两行。我知道我们通常使用 _ 并转到下一行,但是当我在嵌套函数中分解列表时,出现错误:

Compile error: Expected: list separator or )

否则代码工作正常。

我要分割的线是第二条:If Not Intersect(Target, Range [...])

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("F6:F1000000, G6:G1000000, K6:K1000000, L6:L1000000, P6:P1000000, Q6:Q1000000, U6:U1000000, V6:V1000000, Z6:Z1000000, AA6:AA1000000, AE6:AE1000000, AF6:AF1000000")) Is Nothing Then
Application.EnableEvents = False
If ActiveCell.Value = ChrW(&H2713) Then
ActiveCell.ClearContents
Else
ActiveCell.Value = ChrW(&H2713)
End If
Cancel = True
End If
Application.EnableEvents = True
End Sub

谢谢。

最佳答案

代替

Range("F6:F1000000, G6:G1000000, K6:K1000000, L6:L1000000, P6:P1000000, Q6:Q1000000, U6:U1000000, V6:V1000000, Z6:Z1000000, AA6:AA1000000, AE6:AE1000000, AF6:AF1000000")

你也可以用

Range("F6:G1000000, K6:L1000000, P6:Q1000000, U6:V1000000, Z6:AA1000000, AE6:AF1000000")

这只是同一个范围

另一种方法可能是

Dim s1 As String
Dim s2 As String

s1 = "F6:F1000000, G6:G1000000, K6:K1000000, L6:L1000000, P6:P1000000, Q6:Q1000000, "
s2 = "U6:U1000000, V6:V1000000, Z6:Z1000000, AA6:AA1000000, AE6:AE1000000, AF6:AF1000000"

然后使用

Range(s1 & s2)

当然,也可以使用评论中提到的方法

Dim s As String

s = "F6:F1000000, G6:G1000000, K6:K1000000, L6:L1000000, P6:P1000000, Q6:Q1000000, " & _
"U6:U1000000, V6:V1000000, Z6:Z1000000, AA6:AA1000000, AE6:AE1000000, AF6:AF1000000"

关于excel - 如何在 VBA 中将一长行代码分成多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65444296/

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