要了解一下VBA,以及EXCEL里面的一些对象,如:WorkSheet、Range等等。
给你举个简单的例子吧,假设当前工作表里有30行数据,你要取5的倍数行的数量相组合,那么就可以用以下代码来实现。
Sub GetDate()
Dim oRange As Range
Dim i As Integer
Dim intCount As Integer
Dim oSheet As Worksheet
Dim strReturn As String
'// 获取当前活动的工作表
Set oSheet = ActiveSheet
'// 获取当前有效的行数
intCount = oSheet.UsedRange.Cells.Rows.Count
'// 循环取数,步长为5
For i = 5 To intCount Step 5
strReturn = strReturn & "A" & i & "=" & oSheet.Range("A" & i).Value & ","
Next
MsgBox strReturn
Set oRange = Nothing
Set oSheet = Nothing
End Sub