Little Bit Stuck

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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,440
Office Version
365
Platform
Windows
How about
Code:
Sub vonsnapper()
   Dim Cl As Range
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Range("J9", Range("J9").End(xlDown))
         .item(Cl.Value) = Cl.Offset(, 1).Value
      Next Cl
      For Each Cl In Range("D5", Range("D5").End(xlDown))
         Cl.Offset(, 1).Value = .item(Cl.Value)
      Next Cl
   End With
End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
32,440
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Forum statistics

Threads
1,082,601
Messages
5,366,571
Members
400,902
Latest member
fathima

Some videos you may like

This Week's Hot Topics

Top