我有一组值,就像这样。Excel - 编辑按公共值选择列
5 5 5 5 5 5 9 7 7 6 6 55 5 4 4 7 5 30 10 8 7 6 9 60 9 9 9 9 9 80 20 20 20 20 20 20
假设我想编辑所有的值-1或+1,我该怎么做?我非常新的这一点,任何帮助将不胜感激!谢谢。第一
Excel 2007中
我有一组值,就像这样。Excel - 编辑按公共值选择列
5 5 5 5 5 5 9 7 7 6 6 55 5 4 4 7 5 30 10 8 7 6 9 60 9 9 9 9 9 80 20 20 20 20 20 20
假设我想编辑所有的值-1或+1,我该怎么做?我非常新的这一点,任何帮助将不胜感激!谢谢。第一
Excel 2007中
第一件事,打开VBA编辑器尝试ALT + F11。
下面的代码显示了一种做你想做的事情的方法。
请勿复制并粘贴它。
它可以帮助您开始使用自己的代码。
一个快速的解释:
for
循环遍历一个小范围的单元格,每个单元格的值之后你已经编写了自己的代码,你应该可以通过按F5。
option explicit
sub increment_cell_values()
dim r as long
dim c as long
dim ws as worksheet
set ws = activesheet
for r = 1 to 6
for c = 1 to 6
ws.cells(r,c).value = ws.cells(r,c).value + 1
next c
next r
next ws
end sub
做到这一点无论是在正常的Excel或VBA的最快方法是使用Excel的Paste Special
能力
手动方法
这种技术的乘法例子在这里从Mr Excel提供
VBA方法
从 Zack Barresse代码修改后用于xl07/10,它使用在列A空白单元用于添加
Option Explicit
Sub psAdd()
Dim y As Integer 'The multiplier value, user-defined
Dim x As Range 'Just a blank cell for variable
Dim z As Range 'Selection to work with
Set z = Selection
y = Application.InputBox("Enter amount to add to selection:", _
Title:="Add to selection", Default:=10, Type:=1)
Set x = Cells(Rows.Count, "A").End(xlUp).Offset(1)
If y = 0 Then Exit Sub 'Cancel button will = 0, hence cancel
If x <> "" Then
Exit Sub
Else: x.Value = y
x.Copy
z.PasteSpecial Paste:=xlPasteAll, Operation:=xlAdd
Application.CutCopyMode = False 'Kill copy mode
End If
x.ClearContents 'Back to normal :)
End Sub
什么编程语言?如果你的意思是你想用excel来做这件事,那你就错了。尝试像超级用户那样的地方。 – 2012-03-03 09:06:16
@Ash:我认为鲨鱼想用VBA来做到这一点。 – bernie 2012-03-03 09:12:40