sllaksvb
08-18-2017, 08:02 AM
Hi all,
I am pretty new to VBA and wrote many if statements for one of my projects. Here is my sample code:
If Sheets("Sheet1").cb1.Value = True Then
Sheets("Summary").listmarket.AddItem "United States A"
End If
If Sheets("Sheet1").cb2.Value = True Then
Sheets("Summary").listmarket.AddItem "United States B"
End If
If Sheets("Sheet1").cb3.Value = True Then
Sheets("Summary").listmarket.AddItem "United States C"
End If
If Sheets("Sheet1").cb4.Value = True Then
Sheets("Summary").listmarket.AddItem "Australia"
End If
If Sheets("Sheet1").cb5.Value = True Then
Sheets("Summary").listmarket.AddItem "Austria"
End If
If Sheets("Sheet1").cb6.Value = True Then
Sheets("Summary").listmarket.AddItem "Belgium"
End If
If Sheets("Sheet1").cb7.Value = True Then
Sheets("Summary").listmarket.AddItem "Canada"
End If
If Sheets("Sheet1").cb8.Value = True Then
Sheets("Summary").listmarket.AddItem "Czech Republic"
End If
If Sheets("Sheet1").cb9.Value = True Then
Sheets("Summary").listmarket.AddItem "Denmark"
End If
If Sheets("Sheet1").cb10.Value = True Then
Sheets("Summary").listmarket.AddItem "Finland"
End If
If Sheets("Sheet1").cb11.Value = True Then
Sheets("Summary").listmarket.AddItem "France"
End If
If Sheets("Sheet1").cb12.Value = True Then
Sheets("Summary").listmarket.AddItem "Germany"
End If
The cb# are checkboxes and listmarket is a list box that I've placed on my sheet with the activeX control.
I have several problems with this code that I require help with!
I would like to loop through all the checkboxes in a column and if the value is true, add the value to the list on the other sheet.
Also, I have been trying to refer to a cell instead of adding the countries in " ".
However,
Sheets("Summary").listmarket.AddItem Range("A5").Value does not seem to be working for me.
The cell that I am trying to refer to is a column to the left of where the checkboxes are. So it might be possible to refer to the value using offset?
Any assistance on this matter is greatly appreciated! Thank you.
I am pretty new to VBA and wrote many if statements for one of my projects. Here is my sample code:
If Sheets("Sheet1").cb1.Value = True Then
Sheets("Summary").listmarket.AddItem "United States A"
End If
If Sheets("Sheet1").cb2.Value = True Then
Sheets("Summary").listmarket.AddItem "United States B"
End If
If Sheets("Sheet1").cb3.Value = True Then
Sheets("Summary").listmarket.AddItem "United States C"
End If
If Sheets("Sheet1").cb4.Value = True Then
Sheets("Summary").listmarket.AddItem "Australia"
End If
If Sheets("Sheet1").cb5.Value = True Then
Sheets("Summary").listmarket.AddItem "Austria"
End If
If Sheets("Sheet1").cb6.Value = True Then
Sheets("Summary").listmarket.AddItem "Belgium"
End If
If Sheets("Sheet1").cb7.Value = True Then
Sheets("Summary").listmarket.AddItem "Canada"
End If
If Sheets("Sheet1").cb8.Value = True Then
Sheets("Summary").listmarket.AddItem "Czech Republic"
End If
If Sheets("Sheet1").cb9.Value = True Then
Sheets("Summary").listmarket.AddItem "Denmark"
End If
If Sheets("Sheet1").cb10.Value = True Then
Sheets("Summary").listmarket.AddItem "Finland"
End If
If Sheets("Sheet1").cb11.Value = True Then
Sheets("Summary").listmarket.AddItem "France"
End If
If Sheets("Sheet1").cb12.Value = True Then
Sheets("Summary").listmarket.AddItem "Germany"
End If
The cb# are checkboxes and listmarket is a list box that I've placed on my sheet with the activeX control.
I have several problems with this code that I require help with!
I would like to loop through all the checkboxes in a column and if the value is true, add the value to the list on the other sheet.
Also, I have been trying to refer to a cell instead of adding the countries in " ".
However,
Sheets("Summary").listmarket.AddItem Range("A5").Value does not seem to be working for me.
The cell that I am trying to refer to is a column to the left of where the checkboxes are. So it might be possible to refer to the value using offset?
Any assistance on this matter is greatly appreciated! Thank you.