VBAnoob_Corina
New Member
- Joined
- Apr 17, 2014
- Messages
- 13
Hello everybody,
this is the first time for me to post a question here and I hope that you can understand the problem that I'm currently facing
Furthermore, I'm a total VBA noob (really, I just started a few days ago) and also don't have any programming experience at all. Ok, here I go...
One of my Excel worksheets contains some CheckBoxes (Form Control) which are named automatically (thy have unique names). I need all of these names to be compared with the column entries from another worksheet. If a chechbox name matches the entry, then it should be checked, else it can be left unchecked... Can anyone please help me with the code? The one I have written doesn't work. I'm not even sure whether I understand what it does.
Thank you very much for any advice/help.
Kind regards
Corina
Sub CompareCheckboxNames()
Dim ws As Worksheet
Dim SrchRng
Dim shp As Object
Dim myText As String
Dim c As Range
On Error GoTo ErrHandler
Set ws = Worksheets("Risk Category Checklist")
Set SrchRng = ws.Range("G:G")
myText = shp.OLEFormat.Object.Name.Characters.Text
Set c = SrchRng.Find(myText, LookIn:=xlValues)
With Worksheets("Checklist Structure")
For Each shp In .Shapes
If shp.Type = msoFormControl Then
If shp.FormControlType = xlCheckBox Then
If Not c Is Nothing Then
shp.OLEFormat.Object.Value = False
Else
shp.OLEFormat.Object.Value = True
End If
Exit For
End If
End If
Next
End With
Exit Sub
ErrHandler:
Call MsgBox(Err.Description, vbCritical, "Fehler " & Err.number)
End Sub
this is the first time for me to post a question here and I hope that you can understand the problem that I'm currently facing

One of my Excel worksheets contains some CheckBoxes (Form Control) which are named automatically (thy have unique names). I need all of these names to be compared with the column entries from another worksheet. If a chechbox name matches the entry, then it should be checked, else it can be left unchecked... Can anyone please help me with the code? The one I have written doesn't work. I'm not even sure whether I understand what it does.
Thank you very much for any advice/help.
Kind regards
Corina
Sub CompareCheckboxNames()
Dim ws As Worksheet
Dim SrchRng
Dim shp As Object
Dim myText As String
Dim c As Range
On Error GoTo ErrHandler
Set ws = Worksheets("Risk Category Checklist")
Set SrchRng = ws.Range("G:G")
myText = shp.OLEFormat.Object.Name.Characters.Text
Set c = SrchRng.Find(myText, LookIn:=xlValues)
With Worksheets("Checklist Structure")
For Each shp In .Shapes
If shp.Type = msoFormControl Then
If shp.FormControlType = xlCheckBox Then
If Not c Is Nothing Then
shp.OLEFormat.Object.Value = False
Else
shp.OLEFormat.Object.Value = True
End If
Exit For
End If
End If
Next
End With
Exit Sub
ErrHandler:
Call MsgBox(Err.Description, vbCritical, "Fehler " & Err.number)
End Sub