Excel 2007,基于1列中的值将行从一张纸复制到另一张纸
|
我正在尝试复制一系列行,其中选择的行基于一个单元格中的值。我想对一个单元格中包含相同值的所有行执行此操作,然后继续执行下一个附加值第一个列表的底部。
以下是我尝试解释我希望达到的目标的尝试-希望以上内容可以帮助解释我的更多难题。我已经四处寻找,但还没有找到我想要的。我认为这很简单,也许是。
我收到包含数千行数据和18列的数据转储。基于列P \“ Contract \”的值,我要将整个行复制到新的单个工作表
workingdata
中。并非所有数据都将进入“ 0”工作表。
合同编号为c1234,c1235,c2345等。
实现后,我要做的就是复制和排序,因此将合约号为c1234的所有数据行复制到workingdata
中,然后直接在其下方复制合约号为c1235的所有行,依此类推。
我以为我可以选择范围P:P并进行排序,但无济于事。
Sheets(\"Data Dump\").Select
Columns(\"P:P\").Select
If Selection.Value = \"C1234\" Then
Selection.EntireRow.copy
我知道我应该发布我尝试过的内容,但这将是可悲的,由于某种原因,我似乎无法绕过这个问题。
这是我最近的工作-我知道这里有错误
Dim oWorksheet As Excel.Worksheet
Dim oRangeSource As Excel.Range
Dim oRangeDest As Excel.Range
Set oWorksheet = Worksheets(\"DataDump\")
Set oRangeSource = oWorksheet.Range(\"p:p\")
Set oRangeDest = Worksheets(\"workingdata\")
If oRangeSource=\"CA0004000\" Then Select.EntireRow
Selection.EntireRow.copy
Sheets(\"workingdata\").Select.Paste
End If
最新的努力,但没有排序数据或摆脱不必要的麻烦,我必须做一个手动筛选并排序,从而破坏宏对象
Sub copy()
\'
\' copy Macro
\'
Dim rngContracts As Range: Set rngContracts = Sheets(\"DataDump\").Range(\"P:P\")
Dim wsData As Worksheet
Dim wsFound As Boolean: wsFound = False
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name = \"Working Data\" Then
Set wsData = ws
wsFound = True
Exit For
End If
Next ws
If wsFound = False Then
Application.CutCopyMode = False
ActiveSheet.Range(\"A1\").EntireRow.copy
Set wsData = Sheets.Add(After:=Sheets(Sheets.Count))
wsData.Name = \"Working Data\"
wsData.Range(\"A1\").EntireRow.PasteSpecial xlPasteAll, Transpose:=False
End If
Dim iCell As Range
For Each iCell In rngContracts
If iCell.EntireRow.Hidden = False Then
Application.CutCopyMode = False
iCell.EntireRow.copy
wsData.Range(\"P\" & Rows.Count).End(xlUp).Offset(1, 0).EntireRow.PasteSpecial xlPasteAll, Transpose:=False
End If
Next iCell
Application.CutCopyMode = False
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
最新的attaempt-复制我需要但未排序的数据:
Sub copytest()
\'
\' copytest Macro
\'
Set MR = Sheets(\"data Dump\").Range(\"P:P\")
For Each cell In MR
If cell.Value = \"CA000154\" Then
cell.EntireRow.copy
Sheets(\"working data\").Range(\"A\" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial
End If
If cell.Value = \"CA000220\" Then
cell.EntireRow.copy
Sheets(\"working data\").Range(\"A\" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial
End If
If cell.Value = \"CA000393\" Then
cell.EntireRow.copy
Sheets(\"working data\").Range(\"A\" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial
End If
If cell.Value = \"CA000429\" Then
cell.EntireRow.copy
Sheets(\"working data\").Range(\"A\" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial
End If
Application.CutCopyMode = False
Next
End Sub
没有找到相关结果
已邀请:
1 个回复
僻朵庙惩竣