Enter value at intersection of two values

roxorvoxor

New Member
Joined
Jul 25, 2018
Messages
9
I'm looking to simplify the entry of a tracker. I've created dropdown boxes to enter an associates name, the month they performed an activity, and the activity they performed. I've created a helper cell (BT1) and row (14) using concatenate to aid in a lookup (both unhidden for illustration). I'm having an issue figuring out how to "go to" the intersection of the values (not ranges) and can't find anything online that fits what I need. Below is a screenshot of the tracker. Unfortunately I cannot share the file due to company policy. What I need is to create VBA code to look at cell BS1, intersect with BS4, go to the cell (in this case AK22) and enter an "x" in that spot. Just getting to the intersection of those values is what I really need help with.

1684413324871.png
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi @roxorvoxor. Thanks for posting on MrExcel.

I show you two options, one automatic and one with a button.
I've created a helper cell (BT1) and row (14) using concatenate to aid in a lookup (both unhidden for illustration)
With macros, help cells are not necessary.
The macro can read the data directly from the cells: name "BS4", month "CE4" and activity "CJ4".
This assumes that in cell CE4 (month) you are literally capturing the letters "Jan" for January, "Feb" for February, "Mar" for March, etc.

Option 1 Automatic.

Works automatically when you change the value of any of the 3 cells mentioned above.
Put the following code in the sheet events.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect(Target, Range("BS4:CX5")) Is Nothing Then
    Dim sName As String, sMont As String, sActi As String
    Dim n As Long, col As Long
    Dim dt As Date
    Dim f As Range
    
    sName = Range("BS4").Value
    sMont = Range("CE4").Text
    sActi = Range("CJ4").Value
    
    If sName <> "" And sMont <> "" And sActi <> "" Then
      dt = "01/" & sMont & "/" & Year(Date)
      n = Month(dt) - 1
      Set f = Range("11:11").Find(sActi, , xlValues, xlWhole, , , False)
      If Not f Is Nothing Then
        col = f.Column + n
        Set f = Range("A:A").Find(sName, , xlValues, xlWhole, , , False)
        If Not f Is Nothing Then
          With Cells(f.Row, col)
            .Select
            .Value = "x"
          End With
        End If
      End If
    End If
  End If
End Sub
Note Sheet Event:
Right click the tab of the sheet you want this to work, select view code and paste the code into the window that opens up.​


Option 2 With A Button.

Works when you press a button.
Put the following code in a module.
VBA Code:
Sub Enter_value_at_intersection()
  Dim sName As String, sMont As String, sActi As String
  Dim n As Long, col As Long
  Dim dt As Date
  Dim f As Range
  
  sName = Range("BS4").Value
  sMont = Range("CE4").Text
  sActi = Range("CJ4").Value
  
  If sName <> "" And sMont <> "" And sActi <> "" Then
    dt = "01/" & sMont & "/" & Year(Date)
    n = Month(dt) - 1
    Set f = Range("11:11").Find(sActi, , xlValues, xlWhole, , , False)
    If Not f Is Nothing Then
      col = f.Column + n
      Set f = Range("A:A").Find(sName, , xlValues, xlWhole, , , False)
      If Not f Is Nothing Then
        With Cells(f.Row, col)
          .Select
          .Value = "x"
        End With
      End If
    End If
  End If
End Sub
Note Insert A Module:
Press Alt-F11 to open the VBA editor. From the menu select Insert > Module. On the panel that opens, paste the code previous.​
Create a shape in your sheet and assign the macro "Enter_value_at_intersection".​


--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------
 
Upvote 1
Solution
Hi @roxorvoxor. Thanks for posting on MrExcel.

I show you two options, one automatic and one with a button.

With macros, help cells are not necessary.
The macro can read the data directly from the cells: name "BS4", month "CE4" and activity "CJ4".
This assumes that in cell CE4 (month) you are literally capturing the letters "Jan" for January, "Feb" for February, "Mar" for March, etc.

Option 1 Automatic.

Works automatically when you change the value of any of the 3 cells mentioned above.
Put the following code in the sheet events.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Not Intersect(Target, Range("BS4:CX5")) Is Nothing Then
    Dim sName As String, sMont As String, sActi As String
    Dim n As Long, col As Long
    Dim dt As Date
    Dim f As Range
   
    sName = Range("BS4").Value
    sMont = Range("CE4").Text
    sActi = Range("CJ4").Value
   
    If sName <> "" And sMont <> "" And sActi <> "" Then
      dt = "01/" & sMont & "/" & Year(Date)
      n = Month(dt) - 1
      Set f = Range("11:11").Find(sActi, , xlValues, xlWhole, , , False)
      If Not f Is Nothing Then
        col = f.Column + n
        Set f = Range("A:A").Find(sName, , xlValues, xlWhole, , , False)
        If Not f Is Nothing Then
          With Cells(f.Row, col)
            .Select
            .Value = "x"
          End With
        End If
      End If
    End If
  End If
End Sub
Note Sheet Event:
Right click the tab of the sheet you want this to work, select view code and paste the code into the window that opens up.​


Option 2 With A Button.

Works when you press a button.
Put the following code in a module.
VBA Code:
Sub Enter_value_at_intersection()
  Dim sName As String, sMont As String, sActi As String
  Dim n As Long, col As Long
  Dim dt As Date
  Dim f As Range
 
  sName = Range("BS4").Value
  sMont = Range("CE4").Text
  sActi = Range("CJ4").Value
 
  If sName <> "" And sMont <> "" And sActi <> "" Then
    dt = "01/" & sMont & "/" & Year(Date)
    n = Month(dt) - 1
    Set f = Range("11:11").Find(sActi, , xlValues, xlWhole, , , False)
    If Not f Is Nothing Then
      col = f.Column + n
      Set f = Range("A:A").Find(sName, , xlValues, xlWhole, , , False)
      If Not f Is Nothing Then
        With Cells(f.Row, col)
          .Select
          .Value = "x"
        End With
      End If
    End If
  End If
End Sub
Note Insert A Module:
Press Alt-F11 to open the VBA editor. From the menu select Insert > Module. On the panel that opens, paste the code previous.​
Create a shape in your sheet and assign the macro "Enter_value_at_intersection".​


--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------
I apologize for being MIA. This worked perfectly and now I understand how to do it. Thanks so much, you're a rock star!!!
 
Upvote 0

Forum statistics

Threads
1,215,501
Messages
6,125,169
Members
449,212
Latest member
kenmaldonado

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