我正在尝试将工作表1中的数据(由用户手动更新)复制到工作表2(充当数据库)。我需要编写一个循环代码,它将复制完整的进程列表,然后在其旁边添加用户名。 E.g。
进程列在表1的一列中,用户列在一行中,其编号/名称将更改。当最后一个用户之后有一个空白单元格时,循环需要停止复制。
我是VBA的新手,无法理解我所缺少的东西!
Sheets(1).Activate
'Range(6, cln).Select
Range("J6").Select
Do Until IsEmpty(Selection.Value)
'copy proceses
Range("C8").Select
Range(Selection, Selection.End(xlDown)).Copy
Sheets(2).Activate
Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
'Copy users
Sheets(1).Activate
ActiveCell.Copy
Sheets(2).Activate
Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
Cells(Rows.Count, 3).End(xlUp).Offset(0, -1).PasteSpecial Paste:=xlPasteValues
Range(Selection, Selection.End(xlUp)).PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
ActiveCell.Offset(0, 1).Select
Loop
提前致谢!
答案 0 :(得分:0)
您可以执行以下操作,假设您的流程位于A列,而您的用户位于第1行:
dim resultProcess as variant
dim resultUsers as variant
set rngProcesses = sheets(1).Range("A2:A200")
set rngUsers = sheets(1).range("B1:ZZ1")
set rngTarget = sheets(2).range("A1:A200")
resultProcess = array()
resultUsers = array()
i=0
For Each rng in rngProcesses
process = rng.value
resultProcess[i] = process
i = i + 1
next
j=0
For Each item in rngUsers
user = rng.value
resultUsers[i] = user
j = j + 1
Next
i=0
j=0
for each cell in rngTarget
cell.value = resultProcess[i] + resultUsers[j]
i = i + 1
j = j + 1
next