我想从多个单元格创建一个范围。就像这样:
我想有以下四个牢房:
Cells(4, 7)Cells(4, 8)Cells(8, 7)Cells(8, 8)从文件中提取,然后保存到另一个文件,作为其第一行。
我写了这样的东西:
With mybook.Worksheets(5)
Set sourceRange = .Range(Cells(4, 7), Cells(4, 8),
Cells(8, 7), Cells(8, 8))
End With 我面临的问题是,只有Cells (4,7)和Cells (4,8)出现在摘要表中。
有人能帮帮我吗?
发布于 2013-11-28 09:28:12
非常基本的方法。
Sub Transfer4Cells()
Dim sSht As Worksheet, tSht As Worksheet
Dim sRng As Range, tRng As Range
Dim Rng As Range
Set sSht = ThisWorkbook.Sheets("Sheet1") 'Change as needed.
Set tSht = ThisWorkbook.Sheets("Sheet2") 'Change as needed.
Set sRng = sSht.Range("G4,H4,G8,H8") 'You can add more cells here.
Pos = 1
For Each Rng In sRng
tSht.Cells(1, Pos).Value = Rng.Value
Pos = Pos + 1
Next Rng
End Sub虽然这不是一个完美的解决方案,但是如果您只需要它来提取这4个单元,或者甚至更多的话,这个方法是非常灵活的。
希望这能有所帮助。
https://stackoverflow.com/questions/20261542
复制相似问题