jeudi 18 février 2016

Excel VBA: How to do the same code for several checkboxes to set the checkbox Value

I have in my Excel userform several checkboxes (in total 10) which all should be have the same behavior. It means, when I reload the form the value of the checkbox should change, depending on values from the spreadsheet with the actual selected row.

The following code is working probably for one checkbox:

If Sheet1.Cells(iRow, Sheets("aux").Range("B21")) = "X" Then
    cbERW.Value = True
ElseIf Sheet1.Cells(iRow, Sheets("aux").Range("B21")) = "?" Then
    cbERW.Value = Null
Else
    cbERW.Value = False
End If

How I can do this in the easiest way for multiple checkboxes? But for every checkbox the referring row and column could change. For example, the next one look like this (cbHSAW instead of cbERW, Column B22 instead of B21):

If Sheet1.Cells(iRow, Sheets("aux").Range("B22")) = "X" Then
    cbHSAW.Value = True
ElseIf Sheet1.Cells(iRow, Sheets("aux").Range("B22")) = "?" Then
    cbHSAW.Value = Null
Else
    cbHSAW.Value = False
End If

Anybody knows, how to do this easily?




Aucun commentaire:

Enregistrer un commentaire