我当前的VBA代码从一个工作表中提取并根据条件将数据拆分为2(A列中的值是什么)它根据我当前的代码复制整行
更新代码:
Sub discoCopydata()
'DEFINES THE SHEETS AND THE RANGE USED FOR THE COPY PROCESS
Dim dataSource As Worksheet: Set dataSource = ThisWorkbook.Sheets("Miscellaneous Holds")
Dim dataTargetA As Worksheet: Set dataTargetA = ThisWorkbook.Sheets("CDN")
Dim dataTargetB As Worksheet: Set dataTargetB = ThisWorkbook.Sheets("US")
Dim dataSourceRange As Range: Set dataSourceRange = dataSource _
.Range("A1:A" & dataSource.Cells(dataSource.Rows.Count, "A").End(xlUp).row)
' LOOP CAN BE ADJUSTED TO MULTIPLE CONDITIONS
For Each Cell In dataSourceRange
'IS THE DATA FOR CAN?
If Cell.Value = "CAN" = True Then
dataTargetA.Range("A" & Rows.Count).End(xlUp).Offset(1).EntireRow.Value _
= Cell.EntireRow.Value
'IS THIS US DATA?
ElseIf Cell.Value = "US" Then
dataTargetB.Range("A" & Rows.Count).End(xlUp).Offset(1).EntireRow.Value _
= Cell.EntireRow.Value
End If
Next
End Sub
我需要做的是将其限制在I.E.范围内。从A5:K1000,因为这是我导入的数据的大小。我可以在我的代码范围内做到这一点。我可以将Cell.EntireRow.Value
切换为Cell.Range.Value
,这应该将数据粘贴到正确的单元格范围内吗?
答案 0 :(得分:0)
尝试:
If Cell.Value = "CAN" = True Then
dataTargetA.Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(1,11).Value _
= Cell.Resize(1, 11).Value