![](/img/trans.png)
[英]Copy cells from one sheet to another based on criteria in another cell
[英]How to copy cells from one workbook to another based on multiple criteria
我会尽可能清楚地解释我的问题。 有一张工作簿(让我们命名为触角)。 此表包含天线列表 - 列天线名称,列频率和带有天线参数的列。 另一个工作簿还包含一个工作表。 在这个工作表(让它是rawdata)中有列info3,它对应于天线名称和频率列以及其他列。 我需要一个代码来检查info3和频率(workbook rawdata)中的值/文本是否与天线名称和频率(工作簿触角)中的值/文本相同,然后复制参数(在灰色列中)它对应于其他工作簿中相应列(标记为红色)的天线名称和频率。 列不是顺序的,工作簿rawdata中的列频率是可变的。 最好只检查第一个符号的频率 - 如果是9(900),或1(1800),或2(2100)。 我不知道该怎么做....我很感激这方面的帮助。
这不是代码但是一些指导方针:
Option Explicit
Sub test()
Dim wb1 As Workbook, wb2 As Workbook
Dim LastRow1, LastRow2 As Long
Dim rng1 As Range, rng2 As Range, Position As Range, cell As Range
'Set the two workbooks. Keep in mind that code will works only if you have both workbooks open
Set wb1 = Workbooks("antennalist.xls")
Set wb2 = Workbooks("rawdata.xls")
'Let us assume that data appears in Sheet1 & Column A in both workbooks. Find the last row of column A in both Sheets to create our ranges
With wb1.Worksheets("Sheet1")
LastRow1 = .Cells(.Rows.Count, "A").End(xlUp).Row
Set rng1 = .Range("A" & LastRow1)
End With
With wb2.Worksheets("Sheet1")
LastRow2 = .Cells(.Rows.Count, "A").End(xlUp).Row
Set rng2 = .Range("A" & LastRow2)
End With
'Loop rawdata workbook,Sheet 1 & column A and check:
' 1.If the values of rawdata workbook,Sheet 1 & column A appears also in antennalist workbook,Sheet 1 & column A
' 2.If the value next to them match also (this is for testing purposes so you must change)
For Each cell In rng2
If Application.WorksheetFunction.CountIf(rng1, cell.Value) > 0 And cell.Offset(0, 1).Value = .Range("B" & rng1.Row).Value Then
'If condition met copy from rawdata & paste to antennalist
wb2.Worksheets("Sheet1").Range("A1:A2").Copy wb1.Worksheets("Sheet1").Range("A1:A2")
End If
Next cell
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.