私はこれについて多くの投稿があることを知っていますが、それらのどれも実用的な例がないので、避けなければならない理由を理解します。".Select"を使用しないでExcel-VBAでコーディングする - 実際の例
私はこのテーブルを持っている:私は何をしたいか enter image description here
は、ヘッダーとボトムを選択せずに、私のテーブルのデータ範囲を選択することです。
だから、これは私が思い付いたコードです:
Dim MyDataFirstCell
Dim MyDataLastCell
'Establish the Data Area
ActiveSheet.Range("B1").Select ' My Table starts on Column B
'In the example the table starts at B4, but the user could change for B3, B5, etc. So I want to assure it will find the table.
ActiveCell.Offset(1, 0).Select
Do While IsEmpty(ActiveCell)
DoEvents
ActiveCell.Offset(1, 0).Select
Loop
'The first cell (Header) has been found. I need to select the first cel of my data, so:
ActiveCell.Offset(1, 0).Select
DoEvents
MyDataFirstCell = ActiveCell.Address 'Get the first cell address of Data Area
'Now I need to select the last cell of my table:
Selection.End(xlDown).Select 'Get to Bottom Row of the data
Selection.End(xlToRight).Select 'Get to the last Column and data cell by heading to the righthand end
ActiveCell.Offset(-1, 0).Select ' Select the correct last cell
MyDataLastCell = ActiveCell.Address 'Get the Cell address of the last cell of my data area
'Now I want to select this area:
Range(MyDataFirstCell & ":" & MyDataLastCell).Select
あなたは私に「.Select」を使用せずにこれをコーディングするための理想的な方法を示してもらえますか?
Aditional質問:
- 私はアルファベットの名前でソート同様のテーブルを持っています。どのように最適化されたコードに従って、並べ替えを行うことができますか?
- 同じテーブルを2行または3行下に配置している場合、同時にソートを行うことは可能ですか、それとも2つの異なるマクロを作成する必要がありますか?
ご協力いただきありがとうございます。繰り返しますが、投稿されたものは本当に私を助けませんでした。
をすべての時間を参照され非常に良いほとんどキヤノンのポストがあります:http://stackoverflow.com/questions/10714251/how-to-avoid -using-select-in-excel-vba-macros –
また、[Last Used Cell](http://stackoverflow.com/questions/11169445/error-in-finding-html)を見つける最善の方法を検索することもできます。最後に使用されたcell-in-vba「Canon Answer」も参照)。 –
最後のセルを見つけるには:http://stackoverflow.com/questions/11169445/error-in-finding-last-used-cell-in-vba –