即使你已經在你的代碼中提到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