Sub appli01_02()
Dim n As Long, i As Long
Dim from_col As Long, to_col As Long
Dim skip_row As Long, initial_row As Long
Dim max_row As Long
' #### 以下の4つの数字を変更してください。
from_col = 1 ' 1列目から (A列)
to_col = 2 ' 2列目に (B列)
skip_row = 2 ' 何行おきにデータを取るか
initial_row = 1 ' 最初のデータは何行目とするか
' #### 以下実装。変更不要。
Dim sheet As Object, rang As Object, cur As Object
sheet = ThisComponent.Sheets(0)
rang = sheet.getCellRangeByName("A1")
cur = sheet.createCursorByRange(rang)
cur.gotoEndOfUsedArea(True)
max_row = cur.Rows.Count
n=0
For i = max_row - 1 To 0 Step -1
If ThisComponent.Sheets(0).getCellByPosition(from_col - 1, i).getType() <> _
com.sun.star.table.CellContentType.EMPTY Then
Exit For
End If
n = n + 1
Next i
n = max_row - n
ThisComponent.addActionLock()
For i = initial_row To n Step skip_row
If ThisComponent.Sheets(0).getCellByPosition(from_col - 1, i - 1).getType() <> _
com.sun.star.table.CellContentType.EMPTY Then
ThisComponent.Sheets(0).getCellByPosition(to_col - 1, (i - initial_row) \ skip_row).Value = _
ThisComponent.Sheets(0).getCellByPosition(from_col - 1, i - 1).Value
End If
Next i
ThisComponent.removeActionLock()
End Sub
|