How to set an automatically genertaed Option Button to 'True' based on the value in another range in VBA?











up vote
4
down vote

favorite
1












I have generated the radio buttons with the help of the answer to another question, How to set an automatically generated radio button to true in VBA?.



My requirement is to set the automatically generated Option button to 'True' When there is a value 'x' in another sheet. Please refer the picture.



Figure 1: The source to check the value,



enter image description here



Figure 2: The sheet to which the Mark 'x' should be reflected as True.



enter image description here



The Radio buttons that are generated are as Indexed as OB2_2 for the option button in 2 row and 2 coloumn.



Here is the code with which I have been trying,



Private Sub AddOptionButtons(ByRef TargetRange As Range)

Dim m As Variant
m = Sheets("ALLO").Range("D23").Value + 1

Sheets("Final").Range("A2:A" & m).Copy Destination:=Sheets("Int_Result").Range("A2:A" & m)

Dim oCell As Range
For Each oCell In TargetRange
oCell.RowHeight = 20
oCell.ColumnWidth = 6
Dim oOptionButton As OLEObject
Set oOptionButton = TargetRange.Worksheet.OLEObjects.Add(ClassType:="Forms.OptionButton.1", Left:=oCell.Left + 1, Top:=oCell.Top + 1, Width:=15, Height:=18)
oOptionButton.Name = "OB" & oCell.row & "_" & oCell.Column
oOptionButton.Object.GroupName = "grp" & oCell.Top


Next
Call OB2_Click(oCell)

End Sub

Sub OB2_Click(oCell)

Dim col, ro, m As Variant
Dim Shap As Shape
m = Sheets("ALLO").Range("D23").Value + 1

For Each Shap In Sheets("Int_Result").Shapes
For ro = 2 To m Step 1
For col = 1 To 13 Step 1
If Sheets("Final").Cells(ro, col).Value = "" Then
Sheets("Int_Result").Shapes(ro, col).ControlFormat.Value = False
Else
Sheets("Int_Result").Shapes(ro, col).ControlFormat.Value = True
End If
Next col
Next ro
Next Shap

End Sub


When I tried this Code, I got an Error Message " Object variable or With block variable not set" or "Wrong number of arguments or Invalid Property assignment". Guide me to access the automatically generated Radio buttons.



Please, Help me in this regard. Thank you in advance!










share|improve this question




















  • 1




    What line do you get an error on?
    – Marcucciboy2
    Nov 14 at 13:26










  • Hi, there, I get an error in this Line, Sheets("Int_Result").Shapes(ro, col).ControlFormat.Value = False
    – Moghen
    Nov 14 at 13:28






  • 1




    Shapes(ro, col) Shapes only takes one argument
    – Nathan_Sav
    Nov 14 at 13:37






  • 4




    May try using Sheets("Int_Result").OLEObjects("OB" & ro & "_" & Col) instead of Sheets("Int_Result").Shapes(ro, col)
    – Ahmed AU
    Nov 14 at 13:42






  • 1




    If you try to specify an OLEObject that doesn't exist you'd get that error. (eg if you only had 4 objects and you tried to tell excel to adjust the object 5, it would give you this error)
    – Marcucciboy2
    Nov 14 at 14:10















up vote
4
down vote

favorite
1












I have generated the radio buttons with the help of the answer to another question, How to set an automatically generated radio button to true in VBA?.



My requirement is to set the automatically generated Option button to 'True' When there is a value 'x' in another sheet. Please refer the picture.



Figure 1: The source to check the value,



enter image description here



Figure 2: The sheet to which the Mark 'x' should be reflected as True.



enter image description here



The Radio buttons that are generated are as Indexed as OB2_2 for the option button in 2 row and 2 coloumn.



Here is the code with which I have been trying,



Private Sub AddOptionButtons(ByRef TargetRange As Range)

Dim m As Variant
m = Sheets("ALLO").Range("D23").Value + 1

Sheets("Final").Range("A2:A" & m).Copy Destination:=Sheets("Int_Result").Range("A2:A" & m)

Dim oCell As Range
For Each oCell In TargetRange
oCell.RowHeight = 20
oCell.ColumnWidth = 6
Dim oOptionButton As OLEObject
Set oOptionButton = TargetRange.Worksheet.OLEObjects.Add(ClassType:="Forms.OptionButton.1", Left:=oCell.Left + 1, Top:=oCell.Top + 1, Width:=15, Height:=18)
oOptionButton.Name = "OB" & oCell.row & "_" & oCell.Column
oOptionButton.Object.GroupName = "grp" & oCell.Top


Next
Call OB2_Click(oCell)

End Sub

Sub OB2_Click(oCell)

Dim col, ro, m As Variant
Dim Shap As Shape
m = Sheets("ALLO").Range("D23").Value + 1

For Each Shap In Sheets("Int_Result").Shapes
For ro = 2 To m Step 1
For col = 1 To 13 Step 1
If Sheets("Final").Cells(ro, col).Value = "" Then
Sheets("Int_Result").Shapes(ro, col).ControlFormat.Value = False
Else
Sheets("Int_Result").Shapes(ro, col).ControlFormat.Value = True
End If
Next col
Next ro
Next Shap

End Sub


When I tried this Code, I got an Error Message " Object variable or With block variable not set" or "Wrong number of arguments or Invalid Property assignment". Guide me to access the automatically generated Radio buttons.



Please, Help me in this regard. Thank you in advance!










share|improve this question




















  • 1




    What line do you get an error on?
    – Marcucciboy2
    Nov 14 at 13:26










  • Hi, there, I get an error in this Line, Sheets("Int_Result").Shapes(ro, col).ControlFormat.Value = False
    – Moghen
    Nov 14 at 13:28






  • 1




    Shapes(ro, col) Shapes only takes one argument
    – Nathan_Sav
    Nov 14 at 13:37






  • 4




    May try using Sheets("Int_Result").OLEObjects("OB" & ro & "_" & Col) instead of Sheets("Int_Result").Shapes(ro, col)
    – Ahmed AU
    Nov 14 at 13:42






  • 1




    If you try to specify an OLEObject that doesn't exist you'd get that error. (eg if you only had 4 objects and you tried to tell excel to adjust the object 5, it would give you this error)
    – Marcucciboy2
    Nov 14 at 14:10













up vote
4
down vote

favorite
1









up vote
4
down vote

favorite
1






1





I have generated the radio buttons with the help of the answer to another question, How to set an automatically generated radio button to true in VBA?.



My requirement is to set the automatically generated Option button to 'True' When there is a value 'x' in another sheet. Please refer the picture.



Figure 1: The source to check the value,



enter image description here



Figure 2: The sheet to which the Mark 'x' should be reflected as True.



enter image description here



The Radio buttons that are generated are as Indexed as OB2_2 for the option button in 2 row and 2 coloumn.



Here is the code with which I have been trying,



Private Sub AddOptionButtons(ByRef TargetRange As Range)

Dim m As Variant
m = Sheets("ALLO").Range("D23").Value + 1

Sheets("Final").Range("A2:A" & m).Copy Destination:=Sheets("Int_Result").Range("A2:A" & m)

Dim oCell As Range
For Each oCell In TargetRange
oCell.RowHeight = 20
oCell.ColumnWidth = 6
Dim oOptionButton As OLEObject
Set oOptionButton = TargetRange.Worksheet.OLEObjects.Add(ClassType:="Forms.OptionButton.1", Left:=oCell.Left + 1, Top:=oCell.Top + 1, Width:=15, Height:=18)
oOptionButton.Name = "OB" & oCell.row & "_" & oCell.Column
oOptionButton.Object.GroupName = "grp" & oCell.Top


Next
Call OB2_Click(oCell)

End Sub

Sub OB2_Click(oCell)

Dim col, ro, m As Variant
Dim Shap As Shape
m = Sheets("ALLO").Range("D23").Value + 1

For Each Shap In Sheets("Int_Result").Shapes
For ro = 2 To m Step 1
For col = 1 To 13 Step 1
If Sheets("Final").Cells(ro, col).Value = "" Then
Sheets("Int_Result").Shapes(ro, col).ControlFormat.Value = False
Else
Sheets("Int_Result").Shapes(ro, col).ControlFormat.Value = True
End If
Next col
Next ro
Next Shap

End Sub


When I tried this Code, I got an Error Message " Object variable or With block variable not set" or "Wrong number of arguments or Invalid Property assignment". Guide me to access the automatically generated Radio buttons.



Please, Help me in this regard. Thank you in advance!










share|improve this question















I have generated the radio buttons with the help of the answer to another question, How to set an automatically generated radio button to true in VBA?.



My requirement is to set the automatically generated Option button to 'True' When there is a value 'x' in another sheet. Please refer the picture.



Figure 1: The source to check the value,



enter image description here



Figure 2: The sheet to which the Mark 'x' should be reflected as True.



enter image description here



The Radio buttons that are generated are as Indexed as OB2_2 for the option button in 2 row and 2 coloumn.



Here is the code with which I have been trying,



Private Sub AddOptionButtons(ByRef TargetRange As Range)

Dim m As Variant
m = Sheets("ALLO").Range("D23").Value + 1

Sheets("Final").Range("A2:A" & m).Copy Destination:=Sheets("Int_Result").Range("A2:A" & m)

Dim oCell As Range
For Each oCell In TargetRange
oCell.RowHeight = 20
oCell.ColumnWidth = 6
Dim oOptionButton As OLEObject
Set oOptionButton = TargetRange.Worksheet.OLEObjects.Add(ClassType:="Forms.OptionButton.1", Left:=oCell.Left + 1, Top:=oCell.Top + 1, Width:=15, Height:=18)
oOptionButton.Name = "OB" & oCell.row & "_" & oCell.Column
oOptionButton.Object.GroupName = "grp" & oCell.Top


Next
Call OB2_Click(oCell)

End Sub

Sub OB2_Click(oCell)

Dim col, ro, m As Variant
Dim Shap As Shape
m = Sheets("ALLO").Range("D23").Value + 1

For Each Shap In Sheets("Int_Result").Shapes
For ro = 2 To m Step 1
For col = 1 To 13 Step 1
If Sheets("Final").Cells(ro, col).Value = "" Then
Sheets("Int_Result").Shapes(ro, col).ControlFormat.Value = False
Else
Sheets("Int_Result").Shapes(ro, col).ControlFormat.Value = True
End If
Next col
Next ro
Next Shap

End Sub


When I tried this Code, I got an Error Message " Object variable or With block variable not set" or "Wrong number of arguments or Invalid Property assignment". Guide me to access the automatically generated Radio buttons.



Please, Help me in this regard. Thank you in advance!







excel vba excel-vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 at 8:27









Pᴇʜ

19.9k42650




19.9k42650










asked Nov 14 at 13:21









Moghen

407




407








  • 1




    What line do you get an error on?
    – Marcucciboy2
    Nov 14 at 13:26










  • Hi, there, I get an error in this Line, Sheets("Int_Result").Shapes(ro, col).ControlFormat.Value = False
    – Moghen
    Nov 14 at 13:28






  • 1




    Shapes(ro, col) Shapes only takes one argument
    – Nathan_Sav
    Nov 14 at 13:37






  • 4




    May try using Sheets("Int_Result").OLEObjects("OB" & ro & "_" & Col) instead of Sheets("Int_Result").Shapes(ro, col)
    – Ahmed AU
    Nov 14 at 13:42






  • 1




    If you try to specify an OLEObject that doesn't exist you'd get that error. (eg if you only had 4 objects and you tried to tell excel to adjust the object 5, it would give you this error)
    – Marcucciboy2
    Nov 14 at 14:10














  • 1




    What line do you get an error on?
    – Marcucciboy2
    Nov 14 at 13:26










  • Hi, there, I get an error in this Line, Sheets("Int_Result").Shapes(ro, col).ControlFormat.Value = False
    – Moghen
    Nov 14 at 13:28






  • 1




    Shapes(ro, col) Shapes only takes one argument
    – Nathan_Sav
    Nov 14 at 13:37






  • 4




    May try using Sheets("Int_Result").OLEObjects("OB" & ro & "_" & Col) instead of Sheets("Int_Result").Shapes(ro, col)
    – Ahmed AU
    Nov 14 at 13:42






  • 1




    If you try to specify an OLEObject that doesn't exist you'd get that error. (eg if you only had 4 objects and you tried to tell excel to adjust the object 5, it would give you this error)
    – Marcucciboy2
    Nov 14 at 14:10








1




1




What line do you get an error on?
– Marcucciboy2
Nov 14 at 13:26




What line do you get an error on?
– Marcucciboy2
Nov 14 at 13:26












Hi, there, I get an error in this Line, Sheets("Int_Result").Shapes(ro, col).ControlFormat.Value = False
– Moghen
Nov 14 at 13:28




Hi, there, I get an error in this Line, Sheets("Int_Result").Shapes(ro, col).ControlFormat.Value = False
– Moghen
Nov 14 at 13:28




1




1




Shapes(ro, col) Shapes only takes one argument
– Nathan_Sav
Nov 14 at 13:37




Shapes(ro, col) Shapes only takes one argument
– Nathan_Sav
Nov 14 at 13:37




4




4




May try using Sheets("Int_Result").OLEObjects("OB" & ro & "_" & Col) instead of Sheets("Int_Result").Shapes(ro, col)
– Ahmed AU
Nov 14 at 13:42




May try using Sheets("Int_Result").OLEObjects("OB" & ro & "_" & Col) instead of Sheets("Int_Result").Shapes(ro, col)
– Ahmed AU
Nov 14 at 13:42




1




1




If you try to specify an OLEObject that doesn't exist you'd get that error. (eg if you only had 4 objects and you tried to tell excel to adjust the object 5, it would give you this error)
– Marcucciboy2
Nov 14 at 14:10




If you try to specify an OLEObject that doesn't exist you'd get that error. (eg if you only had 4 objects and you tried to tell excel to adjust the object 5, it would give you this error)
– Marcucciboy2
Nov 14 at 14:10












1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










You need to use



 Sheets("Int_Result").OLEObjects("OB2_2").Object.Value = True


Set loop not for shapes, but normal to last row and last column.



So for example:



Dim oCell As Range
Dim LastCell As Range
For Each oCell In TargetRange
oCell.RowHeight = 20
oCell.ColumnWidth = 6
Dim oOptionButton As OLEObject
Set oOptionButton = TargetRange.Worksheet.OLEObjects.Add(ClassType:="Forms.OptionButton.1", Left:=oCell.Left + 1, Top:=oCell.Top + 1, Width:=15, Height:=18)
oOptionButton.Name = "OB" & oCell.Row & "_" & oCell.Column
oOptionButton.Object.GroupName = "grp" & oCell.Top
Set LastCell = oCell

Next
Call OB2_Click(LastCell)




Sub OB2_Click(oCell as Range)

Dim col As Long, ro As Long
dim m as long, k as long

col = oCell.Column
ro = oCell.Row

For m = 2 to ro
For k = 2 to col
If Sheets("Final").Cells(m, k).Value = "" Then
Sheets("Int_Result").OLEObjects("OB" & m & "_" & k).Object.Value = False
Else
Sheets("Int_Result").OLEObjects("OB" & m & "_" & k).Object.Value = True
End If
Next k
Next m
End sub





share|improve this answer























  • Hallo @Gadziu, Thank for your answer. I have tried your codes, An error stating "Object Variable or With block variable not Set". I actually planned to reference each cell in 'Int_Result' sheet and access the shape present in the cell. which makes the solution simple. But I have problems with the Syntax with which I can refer each Shape in the sheet.
    – Moghen
    Nov 14 at 14:47






  • 2




    My solution works. You have this error, because you pass as oCell empty object. After you escape from each for loop your oCell is null. You need to remeber it in other object. Solutions above.
    – Gadziu
    Nov 14 at 14:48










  • Hi @Gadziu, It worked really great. I thank you very much for the efforts you have put forth to help me. I still have a small question. In the call statement Call OB2_Click(LastCell) the arguement is LastCell, but when you are opening the subroutine OB2_Click you use oCell. Can you please explain me, how that exactly works? #New to programming dude.
    – Moghen
    Nov 14 at 15:34






  • 1




    I passes LastCell from AddOptionButtons, but in OB2_Click I have oCell as Range, so I need to use oCell
    – Gadziu
    Nov 14 at 15:37










  • I was thinking that the arguement which we pass in the Call statement and the argument we get in the Subroutine should be same. Learned that, It could also be different. Thank you once again.
    – Moghen
    Nov 14 at 15:39











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301224%2fhow-to-set-an-automatically-genertaed-option-button-to-true-based-on-the-value%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










You need to use



 Sheets("Int_Result").OLEObjects("OB2_2").Object.Value = True


Set loop not for shapes, but normal to last row and last column.



So for example:



Dim oCell As Range
Dim LastCell As Range
For Each oCell In TargetRange
oCell.RowHeight = 20
oCell.ColumnWidth = 6
Dim oOptionButton As OLEObject
Set oOptionButton = TargetRange.Worksheet.OLEObjects.Add(ClassType:="Forms.OptionButton.1", Left:=oCell.Left + 1, Top:=oCell.Top + 1, Width:=15, Height:=18)
oOptionButton.Name = "OB" & oCell.Row & "_" & oCell.Column
oOptionButton.Object.GroupName = "grp" & oCell.Top
Set LastCell = oCell

Next
Call OB2_Click(LastCell)




Sub OB2_Click(oCell as Range)

Dim col As Long, ro As Long
dim m as long, k as long

col = oCell.Column
ro = oCell.Row

For m = 2 to ro
For k = 2 to col
If Sheets("Final").Cells(m, k).Value = "" Then
Sheets("Int_Result").OLEObjects("OB" & m & "_" & k).Object.Value = False
Else
Sheets("Int_Result").OLEObjects("OB" & m & "_" & k).Object.Value = True
End If
Next k
Next m
End sub





share|improve this answer























  • Hallo @Gadziu, Thank for your answer. I have tried your codes, An error stating "Object Variable or With block variable not Set". I actually planned to reference each cell in 'Int_Result' sheet and access the shape present in the cell. which makes the solution simple. But I have problems with the Syntax with which I can refer each Shape in the sheet.
    – Moghen
    Nov 14 at 14:47






  • 2




    My solution works. You have this error, because you pass as oCell empty object. After you escape from each for loop your oCell is null. You need to remeber it in other object. Solutions above.
    – Gadziu
    Nov 14 at 14:48










  • Hi @Gadziu, It worked really great. I thank you very much for the efforts you have put forth to help me. I still have a small question. In the call statement Call OB2_Click(LastCell) the arguement is LastCell, but when you are opening the subroutine OB2_Click you use oCell. Can you please explain me, how that exactly works? #New to programming dude.
    – Moghen
    Nov 14 at 15:34






  • 1




    I passes LastCell from AddOptionButtons, but in OB2_Click I have oCell as Range, so I need to use oCell
    – Gadziu
    Nov 14 at 15:37










  • I was thinking that the arguement which we pass in the Call statement and the argument we get in the Subroutine should be same. Learned that, It could also be different. Thank you once again.
    – Moghen
    Nov 14 at 15:39















up vote
3
down vote



accepted










You need to use



 Sheets("Int_Result").OLEObjects("OB2_2").Object.Value = True


Set loop not for shapes, but normal to last row and last column.



So for example:



Dim oCell As Range
Dim LastCell As Range
For Each oCell In TargetRange
oCell.RowHeight = 20
oCell.ColumnWidth = 6
Dim oOptionButton As OLEObject
Set oOptionButton = TargetRange.Worksheet.OLEObjects.Add(ClassType:="Forms.OptionButton.1", Left:=oCell.Left + 1, Top:=oCell.Top + 1, Width:=15, Height:=18)
oOptionButton.Name = "OB" & oCell.Row & "_" & oCell.Column
oOptionButton.Object.GroupName = "grp" & oCell.Top
Set LastCell = oCell

Next
Call OB2_Click(LastCell)




Sub OB2_Click(oCell as Range)

Dim col As Long, ro As Long
dim m as long, k as long

col = oCell.Column
ro = oCell.Row

For m = 2 to ro
For k = 2 to col
If Sheets("Final").Cells(m, k).Value = "" Then
Sheets("Int_Result").OLEObjects("OB" & m & "_" & k).Object.Value = False
Else
Sheets("Int_Result").OLEObjects("OB" & m & "_" & k).Object.Value = True
End If
Next k
Next m
End sub





share|improve this answer























  • Hallo @Gadziu, Thank for your answer. I have tried your codes, An error stating "Object Variable or With block variable not Set". I actually planned to reference each cell in 'Int_Result' sheet and access the shape present in the cell. which makes the solution simple. But I have problems with the Syntax with which I can refer each Shape in the sheet.
    – Moghen
    Nov 14 at 14:47






  • 2




    My solution works. You have this error, because you pass as oCell empty object. After you escape from each for loop your oCell is null. You need to remeber it in other object. Solutions above.
    – Gadziu
    Nov 14 at 14:48










  • Hi @Gadziu, It worked really great. I thank you very much for the efforts you have put forth to help me. I still have a small question. In the call statement Call OB2_Click(LastCell) the arguement is LastCell, but when you are opening the subroutine OB2_Click you use oCell. Can you please explain me, how that exactly works? #New to programming dude.
    – Moghen
    Nov 14 at 15:34






  • 1




    I passes LastCell from AddOptionButtons, but in OB2_Click I have oCell as Range, so I need to use oCell
    – Gadziu
    Nov 14 at 15:37










  • I was thinking that the arguement which we pass in the Call statement and the argument we get in the Subroutine should be same. Learned that, It could also be different. Thank you once again.
    – Moghen
    Nov 14 at 15:39













up vote
3
down vote



accepted







up vote
3
down vote



accepted






You need to use



 Sheets("Int_Result").OLEObjects("OB2_2").Object.Value = True


Set loop not for shapes, but normal to last row and last column.



So for example:



Dim oCell As Range
Dim LastCell As Range
For Each oCell In TargetRange
oCell.RowHeight = 20
oCell.ColumnWidth = 6
Dim oOptionButton As OLEObject
Set oOptionButton = TargetRange.Worksheet.OLEObjects.Add(ClassType:="Forms.OptionButton.1", Left:=oCell.Left + 1, Top:=oCell.Top + 1, Width:=15, Height:=18)
oOptionButton.Name = "OB" & oCell.Row & "_" & oCell.Column
oOptionButton.Object.GroupName = "grp" & oCell.Top
Set LastCell = oCell

Next
Call OB2_Click(LastCell)




Sub OB2_Click(oCell as Range)

Dim col As Long, ro As Long
dim m as long, k as long

col = oCell.Column
ro = oCell.Row

For m = 2 to ro
For k = 2 to col
If Sheets("Final").Cells(m, k).Value = "" Then
Sheets("Int_Result").OLEObjects("OB" & m & "_" & k).Object.Value = False
Else
Sheets("Int_Result").OLEObjects("OB" & m & "_" & k).Object.Value = True
End If
Next k
Next m
End sub





share|improve this answer














You need to use



 Sheets("Int_Result").OLEObjects("OB2_2").Object.Value = True


Set loop not for shapes, but normal to last row and last column.



So for example:



Dim oCell As Range
Dim LastCell As Range
For Each oCell In TargetRange
oCell.RowHeight = 20
oCell.ColumnWidth = 6
Dim oOptionButton As OLEObject
Set oOptionButton = TargetRange.Worksheet.OLEObjects.Add(ClassType:="Forms.OptionButton.1", Left:=oCell.Left + 1, Top:=oCell.Top + 1, Width:=15, Height:=18)
oOptionButton.Name = "OB" & oCell.Row & "_" & oCell.Column
oOptionButton.Object.GroupName = "grp" & oCell.Top
Set LastCell = oCell

Next
Call OB2_Click(LastCell)




Sub OB2_Click(oCell as Range)

Dim col As Long, ro As Long
dim m as long, k as long

col = oCell.Column
ro = oCell.Row

For m = 2 to ro
For k = 2 to col
If Sheets("Final").Cells(m, k).Value = "" Then
Sheets("Int_Result").OLEObjects("OB" & m & "_" & k).Object.Value = False
Else
Sheets("Int_Result").OLEObjects("OB" & m & "_" & k).Object.Value = True
End If
Next k
Next m
End sub






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 at 15:40

























answered Nov 14 at 14:23









Gadziu

353116




353116












  • Hallo @Gadziu, Thank for your answer. I have tried your codes, An error stating "Object Variable or With block variable not Set". I actually planned to reference each cell in 'Int_Result' sheet and access the shape present in the cell. which makes the solution simple. But I have problems with the Syntax with which I can refer each Shape in the sheet.
    – Moghen
    Nov 14 at 14:47






  • 2




    My solution works. You have this error, because you pass as oCell empty object. After you escape from each for loop your oCell is null. You need to remeber it in other object. Solutions above.
    – Gadziu
    Nov 14 at 14:48










  • Hi @Gadziu, It worked really great. I thank you very much for the efforts you have put forth to help me. I still have a small question. In the call statement Call OB2_Click(LastCell) the arguement is LastCell, but when you are opening the subroutine OB2_Click you use oCell. Can you please explain me, how that exactly works? #New to programming dude.
    – Moghen
    Nov 14 at 15:34






  • 1




    I passes LastCell from AddOptionButtons, but in OB2_Click I have oCell as Range, so I need to use oCell
    – Gadziu
    Nov 14 at 15:37










  • I was thinking that the arguement which we pass in the Call statement and the argument we get in the Subroutine should be same. Learned that, It could also be different. Thank you once again.
    – Moghen
    Nov 14 at 15:39


















  • Hallo @Gadziu, Thank for your answer. I have tried your codes, An error stating "Object Variable or With block variable not Set". I actually planned to reference each cell in 'Int_Result' sheet and access the shape present in the cell. which makes the solution simple. But I have problems with the Syntax with which I can refer each Shape in the sheet.
    – Moghen
    Nov 14 at 14:47






  • 2




    My solution works. You have this error, because you pass as oCell empty object. After you escape from each for loop your oCell is null. You need to remeber it in other object. Solutions above.
    – Gadziu
    Nov 14 at 14:48










  • Hi @Gadziu, It worked really great. I thank you very much for the efforts you have put forth to help me. I still have a small question. In the call statement Call OB2_Click(LastCell) the arguement is LastCell, but when you are opening the subroutine OB2_Click you use oCell. Can you please explain me, how that exactly works? #New to programming dude.
    – Moghen
    Nov 14 at 15:34






  • 1




    I passes LastCell from AddOptionButtons, but in OB2_Click I have oCell as Range, so I need to use oCell
    – Gadziu
    Nov 14 at 15:37










  • I was thinking that the arguement which we pass in the Call statement and the argument we get in the Subroutine should be same. Learned that, It could also be different. Thank you once again.
    – Moghen
    Nov 14 at 15:39
















Hallo @Gadziu, Thank for your answer. I have tried your codes, An error stating "Object Variable or With block variable not Set". I actually planned to reference each cell in 'Int_Result' sheet and access the shape present in the cell. which makes the solution simple. But I have problems with the Syntax with which I can refer each Shape in the sheet.
– Moghen
Nov 14 at 14:47




Hallo @Gadziu, Thank for your answer. I have tried your codes, An error stating "Object Variable or With block variable not Set". I actually planned to reference each cell in 'Int_Result' sheet and access the shape present in the cell. which makes the solution simple. But I have problems with the Syntax with which I can refer each Shape in the sheet.
– Moghen
Nov 14 at 14:47




2




2




My solution works. You have this error, because you pass as oCell empty object. After you escape from each for loop your oCell is null. You need to remeber it in other object. Solutions above.
– Gadziu
Nov 14 at 14:48




My solution works. You have this error, because you pass as oCell empty object. After you escape from each for loop your oCell is null. You need to remeber it in other object. Solutions above.
– Gadziu
Nov 14 at 14:48












Hi @Gadziu, It worked really great. I thank you very much for the efforts you have put forth to help me. I still have a small question. In the call statement Call OB2_Click(LastCell) the arguement is LastCell, but when you are opening the subroutine OB2_Click you use oCell. Can you please explain me, how that exactly works? #New to programming dude.
– Moghen
Nov 14 at 15:34




Hi @Gadziu, It worked really great. I thank you very much for the efforts you have put forth to help me. I still have a small question. In the call statement Call OB2_Click(LastCell) the arguement is LastCell, but when you are opening the subroutine OB2_Click you use oCell. Can you please explain me, how that exactly works? #New to programming dude.
– Moghen
Nov 14 at 15:34




1




1




I passes LastCell from AddOptionButtons, but in OB2_Click I have oCell as Range, so I need to use oCell
– Gadziu
Nov 14 at 15:37




I passes LastCell from AddOptionButtons, but in OB2_Click I have oCell as Range, so I need to use oCell
– Gadziu
Nov 14 at 15:37












I was thinking that the arguement which we pass in the Call statement and the argument we get in the Subroutine should be same. Learned that, It could also be different. Thank you once again.
– Moghen
Nov 14 at 15:39




I was thinking that the arguement which we pass in the Call statement and the argument we get in the Subroutine should be same. Learned that, It could also be different. Thank you once again.
– Moghen
Nov 14 at 15:39


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301224%2fhow-to-set-an-automatically-genertaed-option-button-to-true-based-on-the-value%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?