Excel精英培训网

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

恳求老师帮忙写出SpinButton初始值为活动单元格值的代码!

[复制链接]
发表于 2016-8-23 14:03 | 显示全部楼层 |阅读模式
比如:图中的a2是活动单元格,点击SpinButton1使活动单元格a2的“17”加1或减1.
1.JPG

工作簿1.zip

15.99 KB, 下载次数: 11

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2016-8-23 14:57 | 显示全部楼层
本帖最后由 Excel学徒123 于 2016-8-23 14:59 编辑
  1. Private Sub SpinButton1_SpinDown()
  2.     DTPicker1.Value = DTPicker1.Value + 1
  3.     [A2] = DTPicker1.Value + 1
  4. End Sub

  5. Private Sub SpinButton1_SpinUp()
  6.     DTPicker1.Value = DTPicker1.Value - 1
  7.     [A2] = DTPicker1.Value - 1
  8. End Sub

  9. Private Sub UserForm_Activate()
  10.     If Len(ActiveCell) > 0 Then
  11.         DTPicker1.Value = ActiveCell
  12.     End If
  13. End Sub
复制代码
代码试试,不知道是否是你要达到的效果
回复

使用道具 举报

 楼主| 发表于 2016-8-23 15:37 | 显示全部楼层
Excel学徒123 发表于 2016-8-23 14:57
代码试试,不知道是否是你要达到的效果

这个代码只选择了a2,我说的是活动单元格。比如活动单元格是a1或a3,或其他单元格时也一样。


回复

使用道具 举报

发表于 2016-8-23 15:41 | 显示全部楼层
  1. Private Sub SpinButton1_SpinDown()
  2.     DTPicker1.Value = DTPicker1.Value + 1
  3.     ActiveCell = DTPicker1.Value + 1
  4. End Sub

  5. Private Sub SpinButton1_SpinUp()
  6.     DTPicker1.Value = DTPicker1.Value - 1
  7.     ActiveCell = DTPicker1.Value - 1
  8. End Sub

  9. Private Sub UserForm_Activate()
  10.     If Len(ActiveCell) > 0 Then
  11.         DTPicker1.Value = ActiveCell
  12.     End If
  13. End Sub
复制代码
回复

使用道具 举报

发表于 2016-8-23 15:42 | 显示全部楼层
一片薄云 发表于 2016-8-23 15:37
这个代码只选择了a2,我说的是活动单元格。比如活动单元格是a1或a3,或其他单元格时也一样。

答案看4楼,把[A2] 改成ACTIVECELL就可以了
回复

使用道具 举报

 楼主| 发表于 2016-8-23 15:52 | 显示全部楼层
本帖最后由 一片薄云 于 2016-8-23 16:10 编辑

非常感谢耐心回答!我表达的不是太清楚。
我的要求是直接更改活动单元格的值,不是改变DTPicker1的值。
比如:如果图中的活动单元格是a3,则控制“31”,如果图中的活动单元格是a1,则控制“12”。
活动单元格原先已有数据,然后选择为活动单元格。谢谢!
回复

使用道具 举报

发表于 2020-2-6 18:50 | 显示全部楼层
求解
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-8-16 03:06 , Processed in 0.186953 second(s), 13 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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