Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 3988|回复: 3

[已解决]把窗体的数据录入到另一个工作表中,不知错在哪里

[复制链接]
发表于 2015-12-13 12:26 | 显示全部楼层 |阅读模式
本帖最后由 ys_zheng 于 2015-12-13 12:31 编辑

以下是窗体上"确定"按钮的代码,要把窗体上的数据保存到sheet13工作表的对应列上,但总是无法录入到sheet13,只能录入到窗体所在的工作表,麻烦老师们帮我看看,错在哪里?
Private Sub CommandButton1_Click()
Dim xrow As Integer
With Sheet13
  xrow = Sheets("人事异动记录").Range("A1").CurrentRegion.Rows.Count + 1
        Cells(xrow, "A") = Sheets("信息录入").Cells(6, 6)
        Cells(xrow, "B") = Sheets("信息录入").Cells(6, 8)
        Cells(xrow, "C") = Sheets("信息录入").Cells(6, 10)
        Cells(xrow, "D") = Sheets("信息录入").Cells(8, 6)
        Cells(xrow, "E") = Sheets("信息录入").Cells(21, 4)
        Cells(xrow, "F") = ComboBox2.Value
        Cells(xrow, "G") = ComboBox3.Value
        Cells(xrow, "H") = TextBox1.Value
        Cells(xrow, "I") = ComboBox1.Value
        Cells(xrow, "J") = ComboBox4.Value
        Cells(xrow, "K") = TextBox2.Value
        Cells(xrow, "L") = TextBox3.Value
        Cells(xrow, "M") = TextBox4.Value
        Cells(xrow, "N") = TextBox5.Value
        Cells(xrow, "O") = TextBox6.Value
        Cells(xrow, "") = TextBox7.Value
        Cells(xrow, "Q") = TextBox8.Value
        Cells(xrow, "R") = TextBox9.Value
        Cells(xrow, "T") = TextBox10.Value
        Cells(xrow, "U") = TextBox11.Value
        Cells(xrow, "V") = TextBox12.Value
        Cells(xrow, "W") = TextBox13.Value
    End With
End Sub
本人初学VBA,所以代码写得有点头痛,请各位将就着帮忙看一下无法录入到sheet13工作中,只能录入到窗体所在的工作表,也没有提示错误,应该是我少了什么。
最佳答案
2015-12-13 13:56
Cells(xrow, "A") = Sheets("信息录入").Cells(6, 6)
所有这个CELLS前面都加一个点(.)试试
 楼主| 发表于 2015-12-13 12:50 | 显示全部楼层
回复

使用道具 举报

发表于 2015-12-13 13:56 | 显示全部楼层    本楼为最佳答案   
Cells(xrow, "A") = Sheets("信息录入").Cells(6, 6)
所有这个CELLS前面都加一个点(.)试试
回复

使用道具 举报

 楼主| 发表于 2015-12-13 15:58 | 显示全部楼层
Look我在这 发表于 2015-12-13 13:56
Cells(xrow, "A") = Sheets("信息录入").Cells(6, 6)
所有这个CELLS前面都加一个点(.)试试

加了一个.就可以了,能说下是为什么吗。刚刚开始学VBA,不懂
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-6-1 09:43 , Processed in 0.176811 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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