Excel VBA 質問スレ Part33
レス数が950を超えています。1000を超えると書き込みができなくなります。
0960935
2014/06/27(金) 02:00:43.32ID:fo8RbvYeCurrentRejion は、関係なかった。(というか>>940の指摘どおりCurrentRejionでは対応出来ない部分があった)Findを4回でどうやるのかも分からないからベタにやった。
適当な範囲をセレクトした状態で以下のマクロを実行すると、データがある範囲だけを包含した矩形の領域をセレクトして終了する……はず。<=ちょっと自信ない
Sub test()
Dim wf As WorksheetFunction
Dim rw_cnt As Long, cl_cnt As Long, st_rw As Long, ed_rw As Long, st_cl As Long, ed_cl As Long
Set wf = Application.WorksheetFunction
With Selection
rw_cnt = .Rows.Count
cl_cnt = .Columns.Count
For st_rw = 1 To rw_cnt
If wf.CountA(.Rows(st_rw)) > 0 Then Exit For
Next st_rw
If st_rw > rw_cnt Then
MsgBox "Err:NoData"
Exit Sub
End If
For ed_rw = rw_cnt To 1 Step -1
If wf.CountA(.Rows(ed_rw)) > 0 Then Exit For
Next ed_rw
For st_cl = 1 To cl_cnt
If wf.CountA(.Columns(st_cl)) > 0 Then Exit For
Next st_cl
For ed_cl = cl_cnt To 1 Step -1
If wf.CountA(.Columns(ed_cl)) > 0 Then Exit For
Next ed_cl
Range(.Cells(st_rw, st_cl), .Cells(ed_rw, ed_cl)).Select
End With
Set wf = Nothing
End Sub
レス数が950を超えています。1000を超えると書き込みができなくなります。