发布网友 发布时间:2023-05-05 10:33
共2个回答
热心网友 时间:2023-12-01 21:35
数据写在AB列,代码如下:
Sub Demo()
Numin = 149.52
Numax = 152.12
Div = 0.3
Discuss = Int((Numax - Numin) / Div)
Remainder = (Numax - Numin) - Discuss * Div
Range("A:B").ClearContents
For i = 0 To Discuss + Application.RoundUp(Remainder, 0)
Cells(i + 1, 1) = i
If i > Discuss Then
Cells(i + 1, 2) = Numax
Else
Cells(i + 1, 2) = Numin + Div * i
End If
Next i
End Sub
实测图:
热心网友 时间:2023-12-01 21:35
数据写在AB列,代码如下:
Sub Demo()
Numin = 149.52
Numax = 152.12
Div = 0.3
Discuss = Int((Numax - Numin) / Div)
Remainder = (Numax - Numin) - Discuss * Div
Range("A:B").ClearContents
For i = 0 To Discuss + Application.RoundUp(Remainder, 0)
Cells(i + 1, 1) = i
If i > Discuss Then
Cells(i + 1, 2) = Numax
Else
Cells(i + 1, 2) = Numin + Div * i
End If
Next i
End Sub
实测图:
热心网友 时间:2023-12-01 21:35
Sub 试一试()
Dim g As Range, i As Double, k As Integer
For i = 149.52 To 152.12 Step 0.3
'确定位置
Set g = Range("C:C").Find("*", , , , , xlPrevious) '在C列逆向查找最末非空格
If g Is Nothing Then
Set g = Range("C1") '如果C列为空列,则确定位置为C1单元格
Else
Set g = g.Offset(1) '如果C列非空列,则确定位置为最末非空格的下方单元格
End If
'输出标题
If k = 0 Then
g.Resize(1, 2) = Array("序号", "数值") '当k=0时输出C和D列标题
Set g = g.Offset(1) '并重新确定位置为下方的单元格
End If
'输出数据
g.Resize(1, 2) = Array(k, i) '输出序号和数值
'序号累加
k = k + 1 'k累加
Next
End Sub
热心网友 时间:2023-12-01 21:35
Sub 试一试()
Dim g As Range, i As Double, k As Integer
For i = 149.52 To 152.12 Step 0.3
'确定位置
Set g = Range("C:C").Find("*", , , , , xlPrevious) '在C列逆向查找最末非空格
If g Is Nothing Then
Set g = Range("C1") '如果C列为空列,则确定位置为C1单元格
Else
Set g = g.Offset(1) '如果C列非空列,则确定位置为最末非空格的下方单元格
End If
'输出标题
If k = 0 Then
g.Resize(1, 2) = Array("序号", "数值") '当k=0时输出C和D列标题
Set g = g.Offset(1) '并重新确定位置为下方的单元格
End If
'输出数据
g.Resize(1, 2) = Array(k, i) '输出序号和数值
'序号累加
k = k + 1 'k累加
Next
End Sub