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
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top