我有来自一个表的值,我正在尝试编写一个VBA宏来移动到另一个工作表,它将放在下一个空行中,
到目前为止我选择的数据是:
'storing the values to be moved
Dim DayID As String
Dim Shift As Integer
Dim Operator As String
Dim Operation As String
Dim PartNum As String
Dim Asset As String
'placing selected cells
Sheets("Raw Data").Select
Range("A10000").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).select
ActiveCell.Value = DayID
我已经到了这一点,看看我曾经使用的只是将日期放在广告中它没有。我是VBA的新手,并不完全明白我在做什么,所以任何帮助都表示赞赏!
我放置数据的列分别在A,M,O,Q,N和P列中,如果有帮助的话
答案 0 :(得分:1)
如果您不完全知道要填写哪些值,您开始使用哪张表以及您希望结果看起来如何,以下内容至少应该让您开始。
Sub test()
Dim rData As Worksheet
Dim lRow As Long
Dim arr(5) As Variant
Set rData = Sheets("Raw Data")
arr(0) = "A"
arr(1) = "M"
arr(2) = "O"
arr(3) = "Q"
arr(4) = "N"
arr(5) = "P"
With rData
For Each element In arr
lRow = .Cells(.Rows.Count, element).End(xlUp).Row + 1
.Cells(lRow, element).Value = "Value in Column " & element
Next element
End With
End Sub
答案 1 :(得分:1)
这假设您正在处理包含代码的同一工作簿。如果没有,您可以将“ThisWorkbook”更改为“ActiveWorkbook”。我包括了With wsTarget
,尽管它当前是过度的,并且相信当你构建这个子程序时,它将变得越来越相关。编辑将前三个变量放入适当的列中。我留给你填写剩下的代码:
Sub FirstStep()
'storing the values to be moved
Dim DayID As String
Dim Shift As Integer
Dim Operator As String
Dim Operation As String
Dim PartNum As String
Dim Asset As String
Dim wsTarget As Worksheet
Set wsTarget = ThisWorkbook.Worksheets("Raw Data") 'Would be much better to change the CodeName of the sheet and reference directly.
'placing selected cells
With wsTarget
.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Value = DayID
.Cells(Rows.Count, 13).End(xlUp).Offset(1, 0).Value = Shift
.Cells(Rows.Count, 15).End(xlUp).Offset(1, 0).Value = Operator
End With
End Sub