即使你已经在你的代码中提到CurrentRegion
,我怀疑你并不需要它至少没有计划在预期的方式来使用它
比方说,我们的工作表看起来是这样的。请注意,在山口F中的公式?
使用.Resize
的问题是,即使它们返回空白值,也会包含具有公式的单元格。
以macroman一致的例子
Sub Sample()
With Sheets("Sheet1").Range("A2").CurrentRegion.Offset(1, 0)
.Resize(.Rows.Count - 1, .Columns.Count).Select
End With
End Sub
我想所有的细胞和值复制它怎么把第一行第二排”是标题/标题。
从我个人理解,你想通过找到最后一排和最后一列具有数据并复制该做的事情。
我认为这是你想要的?注意使用与LookIn:=xlValues
.Find
Sub Sample()
Dim ws As Worksheet
Dim rng As Range
Dim lRow As Long, lCol As Long
Set ws = ThisWorkbook.Sheets("Sheet1")
With ws
lRow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlValues, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
lCol = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlValues, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
Set rng = .Range(.Cells(2, 1), .Cells(lRow, lCol))
Debug.Print rng.Address
rng.Copy
End With
End Sub
[调整其大小(https://msdn.microsoft.com/en-us/library/office/ff196678.aspx)。 – findwindow
当然个人喜好,但可能要删除你的名字从该文件路径... –
@MacroMan没有人会注意到,直到你指出= P – findwindow