Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 如何基于单元格的值复制新工作表中的行_Vba_Excel - Fatal编程技术网

Vba 如何基于单元格的值复制新工作表中的行

Vba 如何基于单元格的值复制新工作表中的行,vba,excel,Vba,Excel,我尝试创建以下宏,但失败: 我有几列的Sheet1,其中一列名为“序列号” 我希望宏添加5个新工作表,名为“Customer1”…“Customer5” 然后浏览名为“序列号”的列,如果该编号是每个客户的组号之一,则复制/粘贴相应工作表中的行。 不同客户的序列号是由5或6位数字组成的组,但不是连续的,因此我必须手动放置它们(例如,如果是1234或2345或7654…->复制/粘贴到Customer1) 我非常感谢你的帮助 尝试这样的方法,不要执行,但要完成任务: Sub go_through_r

我尝试创建以下宏,但失败:

我有几列的Sheet1,其中一列名为“序列号” 我希望宏添加5个新工作表,名为“Customer1”…“Customer5” 然后浏览名为“序列号”的列,如果该编号是每个客户的组号之一,则复制/粘贴相应工作表中的行。 不同客户的序列号是由5或6位数字组成的组,但不是连续的,因此我必须手动放置它们(例如,如果是1234或2345或7654…->复制/粘贴到Customer1


我非常感谢你的帮助

尝试这样的方法,不要执行,但要完成任务:

Sub go_through_rows ()
lastrow = Cells(Rows.count, "A").End(xlUp).Row
for i to lastrow
IF Cells(i,1) = "cutomer ID" OR "cutomer ID2" 'If your customer ID is in row A , if it's in B use 2 instead of 1 here and so on
rows(i & ":" & i).select
selection.copy
SHEETS("target sheet name").activate
CELLS("A1").select
SELECTION.End(XlDOWN).select 'jumps to the last value in the sheet make sure there is data here already
ActiveCell.OFFSET(1, 0).select
Paste
Sheets("sheet with the raw data").activate
ELSE 'nothing
END IF
next i
这可以通过更多的IFs进行调整,并将值添加为变量。
应该可以满足您的需要,但正如前面所说,如果您的数据太大,那么性能就不太好。

到目前为止,您的宏有什么进展?我试图从这里修改一个示例,但失败了(接收到错误,无法理解其中的大部分内容)。为了完成这项任务,我几天前开始阅读有关宏的内容。如何确定给定序列号所属的客户号?我将很快尝试,并会给出反馈。现在谢谢你!