我如何选择一列中的特定值(基于另一列)以与另一列 sheet 中的列匹配以进行复制粘贴?
How do I choose certain values in one column (based on another) to match with a column in another sheet, for the purpose of copy-paste?
我正在尝试遍历 "Sheet1" 中的销售人员(A 列)和客户(B 和 C 列)列表。
我想遍历"Sheet1"的A列,根据销售员,参考B&C列(在那个销售员的范围内),与[=22=的A列比较].如果 "Sheet1" 的 B 列或 C 列中的值与 "Sheet2" 的 A 列中的值匹配,我想复制整行,并将其粘贴到新的 "Sheet3".
我一直在使用循环和条件,已经弄清楚如何根据另一个 sheet 的条件进行复制和粘贴,但是我在指定列 B 和 C 之间苦苦挣扎 link,基于 "Sheet1" 的 A 列,然后将它们与 "Sheet2".
的 A 列匹配
我可以在一个 sheet 中找到一些东西,然后复制并粘贴到另一个 sheet,但这只是我想做的一小部分:
Sub CopyCode()
Dim r As Long, endrow As Long, pasterowindex As Long
endrow = Worksheets("sheet2").Range("A" & Rows.Count).End(xlUp).Row
pasterowindex = 1
For r = 1 To endrow 'Loop through sheet1 and search for your criteria
'Central CODE:
If Worksheets("sheet2").Cells(r, Columns("A").Column).Value = "CLIENT" Then
'get all value(s) in range of column d (and c eventually)
' and see if they match values in column A of Readership paste
'if they do match values in column A of readership paste,
' then copy that matched row into a new sheet
' (will be designated by salesperson)
'Copy the current row
Rows(r).Select
Selection.Copy
'Switch to the sheet where you want to paste it & paste
Sheets("Sheet3").Select
Rows(pasterowindex).Select
ActiveSheet.Paste
'Next time you find a match, it will be pasted in a new row
pasterowindex = pasterowindex + 1
'Switch back to your table & continue to search for your criteria
Sheets("sheet2").Select
End If
Next r
End Sub
for i = FirstRowA to LastRowA 'leaving you to figure out how to find these values
If cell(i) <> vbNullString Then
for h = FirstRowB to LastRowB 'again for you to figure out
If cell(h) = cell(i) Then
cell(h).copy
Sheet2.Cells(Sheet2.Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Sheet2.Cells(Sheet2.Rows.Count, 1).End(xlUp).Offset(0, 1).value = "Column b"
End If
Next h
for j = FirstRowC to LastRowC 'again you figure this out
If cell(j) = cell(i) Then
cell(j).copy
Sheet2.Cells(Sheet2.Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Sheet2.Cells(Sheet2.Rows.Count, 1).End(xlUp).Offset(0, 1).value = "column c"
end if
Next j
end if
next i
这里可能有一些语法问题,但我基本上已经给了你你要求的循环。这只会让您达到可以轻松自己解决其余问题的地步。
我正在尝试遍历 "Sheet1" 中的销售人员(A 列)和客户(B 和 C 列)列表。
我想遍历"Sheet1"的A列,根据销售员,参考B&C列(在那个销售员的范围内),与[=22=的A列比较].如果 "Sheet1" 的 B 列或 C 列中的值与 "Sheet2" 的 A 列中的值匹配,我想复制整行,并将其粘贴到新的 "Sheet3".
我一直在使用循环和条件,已经弄清楚如何根据另一个 sheet 的条件进行复制和粘贴,但是我在指定列 B 和 C 之间苦苦挣扎 link,基于 "Sheet1" 的 A 列,然后将它们与 "Sheet2".
的 A 列匹配我可以在一个 sheet 中找到一些东西,然后复制并粘贴到另一个 sheet,但这只是我想做的一小部分:
Sub CopyCode()
Dim r As Long, endrow As Long, pasterowindex As Long
endrow = Worksheets("sheet2").Range("A" & Rows.Count).End(xlUp).Row
pasterowindex = 1
For r = 1 To endrow 'Loop through sheet1 and search for your criteria
'Central CODE:
If Worksheets("sheet2").Cells(r, Columns("A").Column).Value = "CLIENT" Then
'get all value(s) in range of column d (and c eventually)
' and see if they match values in column A of Readership paste
'if they do match values in column A of readership paste,
' then copy that matched row into a new sheet
' (will be designated by salesperson)
'Copy the current row
Rows(r).Select
Selection.Copy
'Switch to the sheet where you want to paste it & paste
Sheets("Sheet3").Select
Rows(pasterowindex).Select
ActiveSheet.Paste
'Next time you find a match, it will be pasted in a new row
pasterowindex = pasterowindex + 1
'Switch back to your table & continue to search for your criteria
Sheets("sheet2").Select
End If
Next r
End Sub
for i = FirstRowA to LastRowA 'leaving you to figure out how to find these values
If cell(i) <> vbNullString Then
for h = FirstRowB to LastRowB 'again for you to figure out
If cell(h) = cell(i) Then
cell(h).copy
Sheet2.Cells(Sheet2.Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Sheet2.Cells(Sheet2.Rows.Count, 1).End(xlUp).Offset(0, 1).value = "Column b"
End If
Next h
for j = FirstRowC to LastRowC 'again you figure this out
If cell(j) = cell(i) Then
cell(j).copy
Sheet2.Cells(Sheet2.Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Sheet2.Cells(Sheet2.Rows.Count, 1).End(xlUp).Offset(0, 1).value = "column c"
end if
Next j
end if
next i
这里可能有一些语法问题,但我基本上已经给了你你要求的循环。这只会让您达到可以轻松自己解决其余问题的地步。