为什么我不能从module2中的公式中获取值到module1?(Why can't I get the value from formula in module2 into module1?

系统教程 行业动态 更新时间:2024-06-14 16:55:58
为什么我不能从module2中的公式中获取值到module1?(Why can't I get the value from formula in module2 into module1?)

我的excel VBA中有三个模块。 我的主要计算是在module1中编写的,我想从module2中调用subs(简化):

模块1:

sub sub_a() 'some syntaks here call sub_b() sheet1.cells(1,1)=a end sub

模块2:

sub sub_b() a=5 end sub

问题是:为什么在sheet1.cells(1,1)中值a不出来? 怎么了?

I have three modules in my excel VBA. My main calculation is written in module1 and i want to call subs from module2 like this (simplified):

module1:

sub sub_a() 'some syntaks here call sub_b() sheet1.cells(1,1)=a end sub

module2:

sub sub_b() a=5 end sub

And the problem is: why in sheet1.cells(1,1) the value a doesn't come out? What's wrong?

最满意答案

是的,你需要将“a”定义为全局变量。 然后它将对其他子程序可见。 例如:

模块1:

sub sub_a() 'some syntaks here call sub_b() sheet1.cells(1,1)=a end sub

模块2:

Global a as integer sub sub_b() a=5 end sub

Yup, you need to define "a" as a global variable. It will then be visible to other subroutines. E.G.:

module1:

sub sub_a() 'some syntaks here call sub_b() sheet1.cells(1,1)=a end sub

module2:

Global a as integer sub sub_b() a=5 end sub

更多推荐

本文发布于:2023-04-10 11:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/e6921515987fd19a6855385bf860e207.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:公式   formula

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!