第一个子中获得的值不会延续到下一个子中,我该如何做?
这只是代码的一小部分,还有许多其他变量和其他用户输入不允许我组合子代码。
Private Sub lbEY_AfterUpdate()
Dim sd As Date
Dim ed As Date
Dim fromd As String
Dim tod As String
sm = Month(DateValue("01-" & lbSM & "-1900"))
em = Month(DateValue("01-" & lbEM & "-1900"))
sd = DateSerial(lbSY, sm, 1)
ed = DateSerial(lbEY, em, 1)
fromd = Format(sd, "mmmm yyyy")
tod = Format(ed, "mmmm yyyy")
End Sub
Private Sub CommandButton2_Click()
Range("A1").Value = "For dates " & fromd & " to " & tod & ":"
'This prints out "For dates to :"
End Sub
例如fromd 是 2019 年 1 月,tod 是 2019 年 3 月。 理想的结果是范围 A1 中的值是“对于 2019 年 1 月至 2019 年 3 月的日期:” 提前致谢!
最佳答案
在过程外部声明变量非常简单,如本例所示:
Dim a As Integer
Sub test1()
a = a + 1
End Sub
Sub test2()
a = a + 1
End Sub
Sub test3()
a = Range("A1").Value
End Sub
我启动了 test3()
,将值 4 放入单元格 A1
后,然后运行了 test1()
两次次和 test2()
一次。然后我在 test1()
中放置一个断点,并在立即窗口中输入:
? a
响应为 7。
关于excel - 如何在子 b 中使用子 a 中找到的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56767837/