为行中的非空单元格创build一个均匀间隔数组的数组
我有一个过程,我试图在macros代码。
对于范围中的每一行:
-
我试图select一个非空的单元格。
-
对于那些单元格,select一个最小值
n_1
。 -
给定一个乘法因子,从最小值开始,即(
n_k = (a^k)*n_1
),创build一个等距数的数组(长度与非空行相同)。
沿着这些线的东西
Dim a As Range, b As Range, number_of_elements as Integer Set a = Range() For Each b In a.Rows Dim newarray as Variant 'initialize new array arr = select_non_empty_cells(b) 'select non empty cells number_of_elements = Ubound(arr) 'get number of elements ReDim newarray(1 To number_of_elements) As Integer 'set the dimension min_val = WorksheetFunction.Min(arr.Value) 'pick minimum value For counter = 1 To number_of_elements 'create new array with equally spaced numbers newarray(counter) = min_val*1.25^counter 'multiplying factor Next counter arr.Value = newarray.Value 'set the non empty range to new values Next
以下是我的数据看起来像。 所以对于第一行我会select1033.2(最小值),并创build新的数组,相同长度的5个元素均匀间隔。 第二行也一样。
也许是这样的:
Sub Korba() Dim i As Long, mini As Long Dim WhichRow As Long Dim factr As Double mini = 3 factr = 1.25 WhichRow = 5 For i = 1 To Columns.Count With Cells(WhichRow, i) If .Value <> "" Then Exit Sub .Value = mini * factr ^ i End With Next i End Sub