2017-12-15 9 views
1

マクロでコードを作成しようとしているプロセスがあります。範囲内のすべての行については 行内に空でないセルの配列を均等に配置する

  1. 私は、行の非空のセルを選択しようとしています。

  2. これらのセルの最小値はn_1です。

  3. 与えられた乗算係数aは、最小値で始まる等間隔番号の配列(空でない行と同じ長さ)、つまり(n_k = (a^k)*n_1)を作成します。

これらの線に沿って何か

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 

そして、以下は私のデータがどのように見えるかです。したがって、最初の行では1033.2(最小値)を選択し、均等に間隔を置いた5つの要素の同じ長さの新しい配列を作成します。 2行目と同じです。

enter image description here

答えて

1

おそらくのようなもの:

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 

enter image description here

+0

のthats役立ちます。ありがとうございました。私は私の質問を編集して、私がしようとしていることについてより詳細に説明しました。 – Koba

関連する問題