ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 1107|回复: 2

[求助] 菜鸟关于vba的问题

[复制链接]

TA的精华主题

TA的得分主题

发表于 2012-3-16 11:42 | 显示全部楼层 |阅读模式
Private Sub CommandButton1_Click()
Dim E, I, S, N, T, F, J, P, LT, A As Integer
E = 0
I = 0
S = 0
N = 0
T = 0
F = 0
J = 0
P = 0
LT = 0
For A = 17 To 105 Step 8
E = Val("TextBox" & A) + E
Next A
For A = 18 To 106 Step 8
I = Val("TextBox" & A) + I
Next A
For A = 19 To 107 Step 8
S = Val("TextBox" & A) + S
Next A
For A = 20 To 108 Step 8
N = Val("TextBox" & A) + N
Next A
For A = 21 To 109 Step 8
T = Val("TextBox" & A) + T
Next A
For A = 22 To 110 Step 8
F = Val("TextBox" & A) + F
Next A
For A = 23 To 111 Step 8
J = Val("TextBox" & A) + J
Next A
For A = 24 To 112 Step 8
P = Val("TextBox" & A) + P
Next A
For A = 17 To 111 Step 2
If "TextBox" & A = "" And "TextBox" & (A + 1) = "" Then LT = LT + 1
Next A
Label1.Caption = "一共48道题,你漏做了" & LT & "题,共计得" & Chr(13) & Chr(10) & "E" & E & "分,I" & I & "分,S" & S & "分,N" & N & "分,T" & T & "分,F" & F & "分,J" & J & "分,P" & P & "分!" & Chr(13) & Chr(10) & "你的优势类型为下面字母组合!”"
If E > I Then TextBox113.Text = "E" Else TextBox113.Text = "I"
If S > N Then TextBox114.Text = "S" Else TextBox114.Text = "N"
If T > F Then TextBox115.Text = "T" Else TextBox115.Text = "F"
If J > P Then TextBox116.Text = "J" Else TextBox116.Text = "P"
End Sub

运行完变量都为0,恳请指正,谢谢!

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-3-20 12:48 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
Private Sub CommandButton1_Click()
Dim E, I, S, N, T, F, J, P, LT, A, B As Integer
For A = 17 To 112
For B = 0 To 11
If A = 17 + B * 8 Then E = E + Val("TEXTBOX" & A)
If A = 18 + B * 8 Then I = I + Val("TEXTBOX" & A)
If A = 19 + B * 8 Then S = S + Val("TEXTBOX" & A)
If A = 20 + B * 8 Then N = N + Val("TEXTBOX" & A)
If A = 21 + B * 8 Then T = T + Val("TEXTBOX" & A)
If A = 22 + B * 8 Then F = F + Val("TEXTBOX" & A)
If A = 23 + B * 8 Then J = J + Val("TEXTBOX" & A)
If A = 24 + B * 8 Then P = P + Val("TEXTBOX" & A)
If Val("TEXTBOX" & A) = 0 Then LT = LT + 1 / 2
Next B
Next A
Label1.Caption = "一共48道题,你漏做了" & LT & "题,共计得" & Chr(13) & Chr(10) & "E" & E & "分,I" & I & "分,S" & S & "分,N" & N & "分,T" & T & "分,F" & F & "分,J" & J & "分,P" & P & "分!" & Chr(13) & Chr(10) & "你的优势类型为下面字母组合!”"
If E > I Then TextBox113.Text = "E" Else TextBox113.Text = "I"
If S > N Then TextBox114.Text = "S" Else TextBox114.Text = "N"
If T > F Then TextBox115.Text = "T" Else TextBox115.Text = "F"
If J > P Then TextBox116.Text = "J" Else TextBox116.Text = "P"
End Sub

简化为上面的形式,仍然不对。

TA的精华主题

TA的得分主题

 楼主| 发表于 2012-3-20 16:54 | 显示全部楼层
解决了,这样改的:
Private Sub CommandButton1_Click()
Dim E, I, S, N, T, F, J, P, LT, A, B As Integer
For A = 17 To 112
    For B = 0 To 11
        If A = 17 + B * 8 Then E = Val(Me("TextBox" & A).Value) + E: GoTo 1
        If A = 18 + B * 8 Then I = I + Val(Me("TextBox" & A).Value): GoTo 1
        If A = 19 + B * 8 Then S = S + Val(Me("TextBox" & A).Value): GoTo 1
        If A = 20 + B * 8 Then N = N + Val(Me("TextBox" & A).Value): GoTo 1
        If A = 21 + B * 8 Then T = T + Val(Me("TextBox" & A).Value): GoTo 1
        If A = 22 + B * 8 Then F = F + Val(Me("TextBox" & A).Value): GoTo 1
        If A = 23 + B * 8 Then J = J + Val(Me("TextBox" & A).Value): GoTo 1
        If A = 24 + B * 8 Then P = P + Val(Me("TextBox" & A).Value): GoTo 1
    Next B
1:
If Val(Me("TextBox" & A).Value) = 0 Then LT = LT + 1 / 2
Next A
Label1.Caption = "一共48道题,你漏做了" & LT & "题,共计得" & Chr(13) & Chr(10) & "E: " & E & "分,I: " & I & "分,S: " & S & "分,N: " & N & "分,T: " & T & "分,F: " & F & "分,J: " & J & "分,P: " & P & "分!" & Chr(13) & Chr(10) & "你的优势类型为下面字母组合!"
If E > I Then TextBox113.Text = "E" Else If E = I Then TextBox113.Text = "?" Else TextBox113.Text = "I"
If S > N Then TextBox114.Text = "S" Else If S = N Then TextBox114.Text = "?" Else TextBox114.Text = "N"
If T > F Then TextBox115.Text = "T" Else If T = F Then TextBox115.Text = "?" Else TextBox115.Text = "F"
If J > P Then TextBox116.Text = "J" Else If J = P Then TextBox116.Text = "?" Else TextBox116.Text = "P"
End Sub
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-24 06:35 , Processed in 0.035544 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表