vonsnapper
New Member
- Joined
- Mar 15, 2018
- Messages
- 12
Hi there. I have been trying to write some code that will compare the value of a cell to all the values in a multidimensional array that a person establishes while using the program. If the value in the active cell matches one of the values in the first dimension (column) of the array, then one cell over from the active cell the value from the second dimension (column) of the array will be pasted in. This runs in a loop so that all values in a list in the "D" column will be compared. The first sub routine works fine but since the array is dynamic and its length can change using a case statement is not the best as the person would have to add/remove statements. It would be better if a person could just loop through the array if possible. The second subroutine sort of works except that it just compares the array position rather than the value of the array the position...also it will only output the value of the array position (1,2) which is not overly helpful. Any thoughts ideas would be greatly appreciated.
Code:
Private Sub CommandButton10_Click()
Dim Kind As Variant
Dim TType As String
Kind = Range("J9", Range("J9").End(xlDown).End(xlToRight))
Range("D5").Select
Do Until ActiveCell.Value = ""
Select Case True
Case ActiveCell.Value = Kind(1, 1)
TType = Kind(1, 2)
Case ActiveCell.Value = Kind(2, 1)
TType = Kind(2, 2)
Case ActiveCell.Value = Kind(3, 1)
TType = Kind(3, 2)
Case ActiveCell.Value = Kind(4, 1)
TType = Kind(4, 2)
Case ActiveCell.Value = Kind(5, 1)
TType = Kind(5, 2)
Case Else
TType = ""
End Select
ActiveCell.Offset(0, 1) = TType
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Private Sub CommandButton10_Click()
Dim Kind As Variant
Dim Tag As String
Dim TType As String
Dim kind2 As Long
Kind = Range("J9", Range("J9").End(xlDown).End(xlToRight))
For kind2 = LBound(Kind, 1) To UBound(Kind, 1)
If kind2 = ActiveCell.Value Then
ActiveCell.Offset(0, 1) = Kind(1, 2)
ActiveCell.Offset(1, 0).Select
End If
Next kind2
End Sub