【问题标题】:Copy if part of the text cell found excel VBA如果找到部分文本单元格,则复制 excel VBA
【发布时间】:2016-07-14 16:08:45
【问题描述】:

我很难写那个 VBA...

附图应该有助于理解我需要做什么

问题:

a) 如果在 Sheet1 Column B 中找到文本“FAA”,则将同一行中的单元格 C 复制到 Sheet2 Column A。

那么,

b) 删除 Sheet1 的 B 行和 C 行中的那些单元格。

【问题讨论】:

  • 您真的要删除列 B 列和列 C 单元格还是只清除它们的内容??

标签: string excel text find vba


【解决方案1】:
With Worksheets("Sheet1")

    For each cel in .Range(.Range("B1"),.Range("B1").End(xlDown))

       If cel.Value Like "*FAA*" Then 
           Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1).Value = cel.Offset(,1).Value
          cel.Resize(1,2).ClearContents

       End If

    Next

   'if you wish to remove the rows entirely use this code, if not comment out   
   .Range(.Range("B1"),.Range("A1").End(xlDown).Offset(,1)).SpecialCells(xlCellTypeBlanks).EntireRow.Delete

End With

【讨论】:

  • 我希望删除 B 列和 C 列单元格,A 列将保持不变...
  • 那么只需注释掉或删除代码中End With@FotoDJ之前的最后一行
  • 最后一行的偏移量 (,1) 是如何工作的,我想不通?
  • cel.Offset(,1).Value?
  • .Range(.Range("B1"),.Range("A1").End(xlDown).Offset(,1))。 - 那部分
猜你喜欢
  • 2018-08-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-24
  • 2013-07-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多