Excel如何在列中搜索值,在同一行中复制不同的单元格并粘贴到单独的工作簿中?

时间:2016-09-12 02:28:57

标签: excel-formula

如何在不同的工作簿中记录所有“失败”的“总”单元格?

Book1
1st num 2nd num total   T/F
5       5       10      TRUE
6       6       3       FALSE
7       7       14      TRUE
8       8       4       FALSE

Book2
total
3
4

例如,在不同的工作簿中,我希望A:1具有值3,A:2具有值4,因为两者都是假的,所有其他值都是真的。我怎样才能做到这一点?我不希望每个数字之间有空格,或者必须手动过滤或删除空格。

true / false是一个下拉菜单,有一个关键表。我不确定这是否会影响答案。

1 个答案:

答案 0 :(得分:1)

可能需要稍微调整,但我希望它有所帮助。

Sub Copy()

  Dim wbDest As Workbook
  Dim wsDest As Worksheet
  Dim wsSource As Worksheet
  Dim iTFCol As Integer
  Dim iLastRow As Integer
  Dim i As Integer
  Dim iDestRow As Integer
  Dim iDestCol As Integer
  Dim iValueCol As Integer

  Set wbDest = Workbooks("Destination.xlsx")
  Set wsSource = ThisWorkbook.Worksheets("Source")
  Set wsDest = wbDest.Worksheets("Destination")

  iDestCol = 1
  iTFCol = 4
  iValueCol = 3
  iLastRow = wsSource.Cells(Rows.Count, iTFCol).End(xlUp).Row


  For i = 1 To iLastRow
    If wsSource.Cells(i, iTFCol).Value = False Then
      iDestRow = wsDest.Cells(Rows.Count, iDestCol).End(xlUp).Row + 1
      wsDest.Cells(iDestRow, iDestCol).Value = wsSource.Cells(i, iValueCol).Value
    End If
  Next i

End Sub