使用SpecialCells进行多列同行复制/粘贴

有没有办法通过使用.SpecialCells(xlCellTypeConstants,1)来抓取列“B”中的所有数字来复制同一行中的单元格?

例:

假设脚本find了带有数字的单元格B2,B4,B5。 我怎样才能复制D2,D4和D5? 我可以这样做,仍然使用specialcells? 最终,我想将这些值复制/粘贴到另一张表的A和B列。

谢谢!

Dim strOutputFile As Variant Dim wbkOut As Workbook Dim tenln As Range Dim tenlnPaste As Range Dim wbkVer As Workbook If strOutputFile(u) Like "*Lines.csv" Then With wbkOut.Worksheets(1) Set tenln = wbkOut.Worksheets(1).Cells(Rows.Count, 2).End(xlUp) Set tenlnPaste = wbkVer.Worksheets("TLines").Range("A" & .Rows.Count).End(xlUp).Offset(1).Resize(tenln.Rows.Count, 1) wbkOut.Worksheets(1).Range("B:B").SpecialCells(xlCellTypeConstants, 1).Copy With wbkVer.Worksheets("TenLines") tenlnPaste.PasteSpecial xlPasteValues End With End With End If 

是。 这其实很简单 做如下:

 Dim rngConst as Range On Error Resume Next Set rngConst = wbkOut.Worksheets(1).Range("B:B").SpecialCells(xlCellTypeConstants, 1) If Not rngConst is Nothing Then rngConst.Copy 'do your pasting Set rngConts = rngConst.Offset(,2) 'for moving from B to D rngConst.Copy 'do your pasting End If On Error Go To 0 

你也可以做到这一点,把它全部复制到1个副本区​​域:

 Dim rngConst as Range On Error Resume Next If Not rngConst is Nothing Set rngConst = wbkOut.Worksheets(1).Range("B:B").SpecialCells(xlCellTypeConstants, 1) Set rngConst = Range(rngConst, rngConst.Offset(,2)) rngConst.Copy 'do your pasting End If On Error Go To 0 

但是这会将数据复制到新的工作表中成为两个连续的列。 它不会从B复制到B,D复制到D。