2013-11-14 17 views
0
Sub WS() 
    Application.ScreenUpdating = False 
    For Each Mar In ActiveWorkbook.Worksheets 
     Mar.Select 
     ActiveCell.Value = Selection.SpecialCells(xlCellTypeLastCell).Address(False, False) 
     ActiveCell.Offset(1, 0).Select 
     Next Mar 
    Application.ScreenUpdating = True 
End Sub 

那麼,如何調用一個值? 我有10張不同的紙張,我想拉出10張不同紙張的最後一個紙盒的地址。將所有工作表的最後單元格值存儲在一張工作表中

+0

目前尚不清楚你試圖達到什麼目的。 –

+0

你有沒有機會嘗試我建議的答案? –

回答

1

嘗試類似這樣的事情。你的問題有點不清楚,因爲你指的是最後一個單元的Address我想拉最後一個單元格的地址),但你也提到了一些關於Value我怎麼稱呼值)。上面的代碼將檢索最後一個單元格的Address,但還包含檢索值的代碼,您只需註釋掉一行並取消註釋另一行。

Sub LastCellAddresses() 
    Dim Mar As Worksheet 
    Dim myValues As Variant 
    Dim i As Integer: i = 1 

    '## Create an Array with one item for each worksheet 
    ReDim myValues(1 To ActiveWorkbook.Worksheets.Count) 

    '## iterate the worksheets and add values to the array 
    For Each Mar In ActiveWorkbook.Worksheets 

     '## Use one of these, depending on what you're trying to do. 
     ' This line returns the ADDRESS 
     myValues(i) = Mar.Cells.SpecialCells(xlCellTypeLastCell).Address 
     ' OR this line returns the VALUES 
     'myValues(i) = Mar.Cells.SpecialCells(xlCellTypeLastCell).Value 
     i = i + 1 
    Next Mar 

    '## Print each value from the array in its own row, from 
    ' the activeCell 
    ' Modify as needed 
    ActiveCell.Resize(UBound(myValues)).Value = Application.Transpose(myValues) 

End Sub 
+0

不應''。地址'是'.Value'? –

+0

@SiddharthRout取決於你想達到什麼,但我讀到:「我想拉最後一個單元格的地址」。 –

+0

+ 1 True :)我讀了標題:D「在一張表中存儲所有工作表的最後單元格值」 –

相關問題