ワークシート内にたくさんのテキストを保存します。私は配列をExcelワークシートの範囲と比較しているサブルーチンを作成しました。私は道に沿って値をチェックするワークシート全体をサイクリングしています。VBA Store 1ユニークの場合のみ新しい行にD配列を追加
何かが動作していないようです。
例アレイ入力
("Dog" , "Cat" , "6" , "Some string like this")
方法によって変更することができ、この入力配列のUBound
あります。
私のコードは、3つのフィールドを正確に比較しているようではありません。 多分何かが配列カウントと混ざっているか、誰かがこれを達成するための良いアイデアを持っていれば、私はどんな助けにも感謝します。
Public Sub storeData(sArray() As Variant)
Dim i As Integer
Dim vLastRow As Integer
Dim vRow As Integer
Dim test As Range
Dim Destination As Range
Dim wl As Worksheets
vRow = 1
vLastRow = Worksheets("word List").Range("A" & Rows.Count).End(xlUp).Row
Debug.Print vLastRow
For vRow = 1 To vLastRow
RollingCheck = 0
For i = 0 To UBound(sArray)
Set test = Worksheets("word List").Cells(vRow, i + 1)
If (Trim(test.text) = Trim(sArray(i)) & Len(test) > 0) Then
' To speed it up I added the len() command in to avoid null string.
' Ideally I wish I could only cycle through rows which have the same
' number of columns to array indicies because this will be dynamic
RollingCheck = RollingCheck + 1
Debug.Print CStr(vRow) & CStr(RollingCheck) & _
Worksheets("word List").Cells(vRow, i + 1).text & "=" & sArray(i)
If (RollingCheck = UBound(sArray)) Then
MsgBox "exit" & CStr(vRow)
' All columns of the worksheet = each index of the array
' thus exit the sub
Exit Sub
End If
End If
Next i
Next vRow
' Value no found through cycling the work sheet,
' thus store the array within the next blank row
Set Destination = Worksheets("Word List").Range("A" & vRow)
Set Destination = Destination.Resize(1, UBound(sArray))
Destination.value = sArray
MsgBox "store" & CStr(vRow)