在我正在处理的工作中,我有一个关键的保存工作表。我创建了一个按钮宏来尝试执行下面的操作。VBA Excel:当数据满足条件时,将数据从一个单元格复制到另一个单元格
我希望能够循环访问一列信息,并且如果某个单元格包含该列中的数据,则从同一行上的另一列中获取数据,然后将其放入表格中其他位置的新单元格中,将其添加到最后的数据片段下面。
我的代码如下:
Sub getLostKeys()
Dim k As Integer
Dim kMove As Integer
Dim cellKeyNum As String
Dim newCellKeyNum As String
Dim Kcolumn As String
Dim Ccolumn As String
Dim refCell As String
Dim outputCell As String
Kcolumn = "K"
Ccolumn = "C"
For k = 2 To 301
If Cells(k, 8) <> "" Then
cellKeyNum = CStr(k)
kMove = k + 6
newCellKeyNum = CStr(kMove)
refCell = Ccolumn & cellKeyNum
outputCell = Kcolumn & newCellKeyNum
Range(outputCell).Value = Range(refCell)
End If
Next k
End Sub
它编译罚款和代码运行并满足条件不错,但它不会移动蜂窝信息向新的小区。
任何帮助将非常感谢!
您使用的变量太多。任何原因? – Masoud
你的数据是什么样的?我不认为*你需要一个宏,你想做什么?如果一个单元格不是空白的,你只是想将该值放在另一列中? – BruceWayne