Add "x" to a matrix

Monikbor

New Member
Joined
Nov 2, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hello,
I have a problem I have not been able to solve:
I am working on a project to manage information about employees' training. In this part of the project I have a macro that is intended to create new posts and add the names of mandatory trainings (for said post) to a matrix.
On page called App I capture Post Name and Type (office, plant, etc.). Below that, I have a list of mandatory trainings (column F). This list comes from a table on sheet called "Obliga".
On colum I of "App" I included some checkboxes for the user to check the trainings that will be mandatory for that new post.
The macro is supposed to:
1. Add the new post to a table on sheet "Training". (This part is working well).
2. Add a column to a table called "Obliga" on "Obliga" sheet. (this part is also working well).
3. Read the names of trainings on column F of "App", compare with the names of trainings on colum C of "Obliga" and write an "x" in the matching rows, last column.
The problem I have is that tThe "x" never gets written. I already check the cell formating, so the problem is not related to font color. How can I get this done?

This is the code I have so far:
VBA Code:
Sub NewPost()
    Dim appSheet As Worksheet
    Dim formationsSheet As Worksheet
    Dim obligSheet As Worksheet
    Dim postesTable As ListObject
    Dim obligTable As ListObject
    Dim newRow As ListRow
    Dim jobName As String
    Dim postType As String
    Dim i As Integer
    Dim lastColIndex As Integer
    Dim lastCol As ListColumn
    Dim trainingName As String
    Dim obligRow As ListRow
    Dim startRowObliga As Long, endRowObliga As Long
  
    ' Define the tables
    Set postesTable = Formations.ListObjects("Postes")
    Set obligTable = Obligatoire.ListObjects("Obliga")
    
    ' Get the job name and post type from the App sheet
    jobName = App.Range("H35").Value
    postType = App.Range("H37").Value

    ' Add the job name and post type to the Postes table
    Set newRow = postesTable.ListRows.Add
    newRow.Range(1, 1).Value = jobName
    newRow.Range(1, 2).Value = postType

    ' Add the job name to the last column of the Obliga table
    obligTable.ListColumns.Add
    lastColIndex = obligTable.ListColumns.Count
    obligTable.HeaderRowRange.Cells(1, lastColIndex).Value = jobName
        
   ' Define the start and end rows for comparison in the "Obliga" table
    startRowObliga = 4 ' assuming the training names start from row 4
    endRowObliga = Obligatoire.Cells(Obligatoire.Rows.Count, "C").End(xlUp).Row
    
    
        ' Locate the checkbox in the current row
        For Each chk In App.CheckBoxes
            ' Check if the checkbox is within the range of rows 42 to 66
        If chk.TopLeftCell.Row >= 42 And chk.TopLeftCell.Row <= 66 Then
            If chk.Value = 1 Then
                ' Get the training name from the same row
                trainingName = App.Cells(chk.TopLeftCell.Row, "F").Value
                
                ' Compare with each training name in the "Obliga" table
                For j = startRowObliga To endRowObliga
                    obligaTrainingName = Obligatoire.Cells(j, "C").Text
                    
                    Debug.Print "Comparing App Training '" & trainingName & "' with Obliga Training '" & obligaTrainingName & "'"
                    
                    If trainingName = obligaTrainingName Then
                        Obligatoire.Cells(j, lastColIndex).Value = "x"
                        Debug.Print "Marked 'x' for training: " & obligaTrainingName
                    End If
                Next j
            End If
        End If
    Next chk

    MsgBox "Information sauvegardée.", vbInformation
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
1. Add another Debug.Print line ACTUALLY comparing the two names.
It doesn't matter what they look on screen, it's whether Excel thinks they are the same or not.
2. Check the length of both names as well, maybe a name contains characters that don't display on screen and the other name doesn't.
 
Upvote 0
1. Add another Debug.Print line ACTUALLY comparing the two names.
It doesn't matter what they look on screen, it's whether Excel thinks they are the same or not.
2. Check the length of both names as well, maybe a name contains characters that don't display on screen and the other name doesn't.
Thanks Special-K99, but that has been covered. Actually, the list in "Obliga" is a LIST created from data in "Formation". Three is no way for them to be different.
 
Upvote 0

Forum statistics

Threads
1,223,875
Messages
6,175,114
Members
452,613
Latest member
amorehouse

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