本文介绍了Excel宏按钮更改更改单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有关如何获取按钮以基于表格更改单元格值的任何想法.假设单元格A1是活动单元格,我希望每次我根据B列中的值单击按钮时都更改此值,只需在列表B1,B2,B3等下单击...
Any ideas on how to get a button to change cell values based on a table. Say cell A1 is the active cell and i want this value changed everytime I click the button based on the values in column B,just going down the list B1, B2,B3 etc...
Private Sub CommandButton1_Click()
Range("A1").Value = Range("B1:B10").Value
End Sub
推荐答案
我假设一旦达到B10值并再次单击,便要返回B1值.
I've assumed that you want to return to the B1 value once you've reached the B10 value and another click is made.
Private Sub CommandButton1_Click()
If IsError(Application.Match(Range("A1").Value, Range("B1:B10"), 0)) Then
Range("A1").Value = Range("B1").Value
ElseIf Application.Match(Range("A1").Value, Range("B1:B10"), 0) = Range("B1:B10").Cells.Count Then
Range("A1").Value = Range("B1").Value
Else
Range("A1").Value = Range("B1").Offset(Application.Match(Range("A1").Value, Range("B1:B10"), 0), 0).Value
End If
End Sub
这篇关于Excel宏按钮更改更改单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!