简体   繁体   English

如何根据多个条件将单元格从一个工作簿复制到另一个工作簿

[英]How to copy cells from one workbook to another based on multiple criteria

I will try to explain my problem as clear as possible. 我会尽可能清楚地解释我的问题。 There is a workbook (lets named it antennalist) with one sheet. 有一张工作簿(让我们命名为触角)。 This sheet contains a list of antennas - column antenna names, column frequency and columns with parameters of the antennas. 此表包含天线列表 - 列天线名称,列频率和带有天线参数的列。 The other workbook contains also one worksheet. 另一个工作簿还包含一个工作表。 In this worksheet (let it be rawdata) have columns info3 which corresponds to antenna names and columns with frequency and other columns too. 在这个工作表(让它是rawdata)中有列info3,它对应于天线名称和频率列以及其他列。 I need a code which will check if the value/text in info3 and frequency (workbook rawdata) is the same as value/text in antenna name and frequency (workbook antennalist), then to copy the parameters (which are in the gray columns) which corresponds to the antenna name and frequency to the corresponding columns (marked in red) in the other workbook. 我需要一个代码来检查info3和频率(workbook rawdata)中的值/文本是否与天线名称和频率(工作簿触角)中的值/文本相同,然后复制参数(在灰色列中)它对应于其他工作簿中相应列(标记为红色)的天线名称和频率。 The columns are not sequentially and the column frequency in workbook rawdata are variable. 列不是顺序的,工作簿rawdata中的列频率是可变的。 It will be good to check the frequency only the first symbol -if is 9 (900), or 1 (1800), or 2 (2100). 最好只检查第一个符号的频率 - 如果是9(900),或1(1800),或2(2100)。 I have no idea how to do it.... I appreciate the help with this. 我不知道该怎么做....我很感激这方面的帮助。

https://imgur.com/Vq6V95E https://imgur.com/psT9Z1h https://imgur.com/Vq6V95E https://imgur.com/psT9Z1h

It's NOT the code BUT some guidelines: 不是代码但是一些指导方针:

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.

相关问题 根据另一个单元格中的条件将单元格从一个工作表复制到另一个工作表 - Copy cells from one sheet to another based on criteria in another cell VBA-根据多个条件从另一张纸复制单元格 - VBA - copy cells from another sheet based on multiple criteria 如何使用 VBA 将基于某些条件的粘贴数据从一个工作簿复制到另一个工作簿(特定单元格)? - How to copy paste data based on some criterias from one workbook to another(specific cells) using VBA? VBA - 根据汇总 Excel 表格上的条件,将工作簿中的不同模板工作表复制到另一个工作簿的多张工作表中 - VBA - copy different template sheets from a workbook, into multiple sheets of another workbook based on criteria on a summary excel sheet 通过检查单元格从一个工作簿复制到另一个工作簿 - Copy from one workbook to another with checking cells 将单元格范围从一个工作簿复制到另一个工作簿 - Copy range of cells from one workbook to another 根据条件将单元格范围从主工作簿复制到多个文件 - Copy range of cells from master workbook onto multiple files based on criteria 如果条件如何将特定单元格从一张纸复制到另一张纸 - How to copy specific cells from one sheet to another meting if criteria VBA 根据条件将数据从一个工作簿复制到另一个工作簿中的特定单元格 - VBA copying data from one workbook to specific cells in another, based on criteria 将基于多个条件的行从一个工作表复制到另一个VBA - Copy Rows Based On Multiple Criteria from one Worksheet to Another VBA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM