मुझे IF-THEN कथन के लिए चेकबॉक्स के मान का उपयोग करने की आवश्यकता है। उपयोगकर्ता द्वारा जांच की जाने वाली चीज़ों के आधार पर, चीजों की गणना करने के तरीके को बदलने के तरीके। हालांकि, मैं यह नहीं समझ सकता कि चेकबॉक्स मानों का उपयोग कैसे करें, या उन्हें कैसे पहचानें। यहाँ कोड मैं अब तक है: सिर्फ एक परीक्षण के रूपमैं Excel VBA 2010 में IF-THEN कथन में चेकबॉक्स का उपयोग कैसे करूं?
Private Sub Workbook_Open()
Range("E1:F7,A1:A4,B1:B4,C1:C3").Select
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Range("A1").Select
Range("A1") = "Time"
Range("B1") = "Specimen Shape"
Range("C1") = "Data Type"
Range("A1:C1").Font.Bold = True
Range("E1") = "Owner"
Range("E2") = "Experiment Date"
Range("E3") = "Specimen ID"
Range("E4") = "Contaminant"
Range("E5") = "Leachant"
Range("E6") = "Temperature"
Range("E7") = "Regression Title"
Range("E1:E7").Font.Bold = True
Columns("A:E").EntireColumn.EntireColumn.Autofit
'Formatting Column A
Columns("A").EntireColumn.ColumnWidth = 9.71
ActiveSheet.CheckBoxes.Add(4, 14.5, 72, 17.25).Select
Selection.Characters.Text = "Days"
Range("A6").Select
ActiveSheet.CheckBoxes.Add(4, 30.5, 73.5, 17.25).Select
Selection.Characters.Text = "Hours"
ActiveSheet.CheckBoxes.Add(4, 45.75, 52.5, 17.25).Select
Selection.Characters.Text = "Minutes"
'Formatting Column B
ActiveSheet.CheckBoxes.Add(58, 14.5, 72, 17.25).Select
Selection.Characters.Text = "Cylinder"
ActiveSheet.CheckBoxes.Add(58, 30.5, 73.5, 17.25).Select
Selection.Characters.Text = "Wafer"
ActiveSheet.CheckBoxes.Add(58, 45.75, 52.5, 17.25).Select
Selection.Characters.Text = "Irregular"
'Formatting Column C
Columns("C").EntireColumn.ColumnWidth = 12.71
ActiveSheet.CheckBoxes.Add(140.5, 14.5, 72, 17.25).Select
Selection.Characters.Text = "Incremental"
ActiveSheet.CheckBoxes.Add(140.5, 30.5, 72, 17.25).Select
Selection.Characters.Text = "Cumulative"
Columns("F").EntireColumn.ColumnWidth = 60
Range("A1:C1").HorizontalAlignment = xlCenter
Range("F1").Select
Dim btn As Button
Dim rng As Range
With Worksheets("Sheet1")
Set rng = .Range("A9:C9")
Set btn = .Buttons.Add(rng.Left, rng.Top, rng.Width, rng.Height)
With btn
.Caption = "After making your selections above, click this button to continue."
.AutoSize = True
.OnAction = "DataInput"
End With
End With
End Sub
क्या मैं इसे करना चाहते हैं, अगर "टाइम" चेकबॉक्स चयनित है, और फिर बटन जारी रखने के लिए दबाया जाता है है, मैं इसे देखना चाहते IF-THEN कथन का उपयोग करके "YAY" जैसी कुछ कहने के लिए। यदि "टाइम" चेकबॉक्स चेक नहीं किया गया है और आप जारी रखें दबाते हैं, तो मैं इसे "AWW ..." कहूंगा।
यही वह है जो मैंने ऐसा करने की कोशिश की, और यह काम नहीं कर रहा है।
Sub DataInput()
If ActiveSheet.Shapes.Range(Array("Check Box 1")).Value = True Then
MsgBox ("Yay")
Else: MsgBox ("Aww")
End If
End Sub
मैं क्या गलत कर रहा हूं?
मैं एक त्रुटि है, "वर्कशीट वर्ग के OLEObjects संपत्ति प्राप्त करने में असमर्थ"। ? – TheTreeMan
1) क्या आपने प्रासंगिक शीट नाम के साथ "शीट 1" को प्रतिस्थापित किया था? 2) क्या आपने प्रासंगिक चेकबॉक्स नाम के साथ "चेकबॉक्स 1" को प्रतिस्थापित किया था? –
हां, यह अभी भी काम नहीं करता है: \ मैंने बस "चेकबॉक्स 1" को देखा, जब से मैंने मैक्रो रिकॉर्ड किया और चेकबॉक्स हटा दिया, मैक्रो था: 'ActiveSheet.Shapes.Range (Array ("चेक बॉक्स 1"))। – TheTreeMan