Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Conditional appearance of checkboxes in Excel

Hello... I want to have an ActiveX checkbox appear in a
cell when text is entered in an adjacent cell. It's a
check-list, and I want the checkbox to appear only when a
list item has been entered. I assume this has to be
accomplished with a macro, but I can't figure out how.
Any help is much appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Conditional appearance of checkboxes in Excel

Right click on the worksheet tab that should have this behavior. Select View
Code and paste this in:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim OLEObj As OLEObject

If Intersect(Target, Range("b3:b99")) Is Nothing Then Exit Sub
If Target.Cells.Count 1 Then Exit Sub

Set OLEObj = Nothing
On Error Resume Next
Set OLEObj = Me.OLEObjects("CB_" & Target.Offset(0, -1).Address(0, 0))
On Error GoTo 0

If OLEObj Is Nothing Then
'keep going
Else
Exit Sub 'already has one
End If

With Target.Offset(0, -1)
Set OLEObj = .Parent.OLEObjects.Add(ClassType:="Forms.CheckBox. 1", _
Link:=False, DisplayAsIcon:=False, _
Left:=.Left, Top:=.Top, _
Width:=.Width, Height:=.Height)

OLEObj.Name = "CB_" & .Address(0, 0)
End With

With OLEObj
.Object.Caption = ""
.Object.Value = True
End With
End Sub

I used a standard naming convention to determine if the checkbox was there or
not. (like: CB_A3). Depending on what you're doing, you may have to determine
if it already exists in a different manner:

This might be safer:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim OLEObj As OLEObject

If Intersect(Target, Range("b3:b99")) Is Nothing Then Exit Sub
If Target.Cells.Count 1 Then Exit Sub

With Target.Offset(0, -1)
For Each OLEObj In Me.OLEObjects
If TypeOf OLEObj.Object Is MSForms.CheckBox Then
If OLEObj.TopLeftCell.Address = .Address Then
Exit Sub
End If
End If
Next OLEObj

Set OLEObj = .Parent.OLEObjects.Add(ClassType:="Forms.CheckBox. 1", _
Link:=False, DisplayAsIcon:=False, _
Left:=.Left, Top:=.Top, _
Width:=.Width, Height:=.Height)

OLEObj.Name = "CB_" & .Address(0, 0)
End With

With OLEObj
.Object.Caption = ""
.Object.Value = True
End With

End Sub


Kelly wrote:

Hello... I want to have an ActiveX checkbox appear in a
cell when text is entered in an adjacent cell. It's a
check-list, and I want the checkbox to appear only when a
list item has been entered. I assume this has to be
accomplished with a macro, but I can't figure out how.
Any help is much appreciated.


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 07 gridline appearance Melissa W Excel Discussion (Misc queries) 3 August 22nd 08 08:00 PM
conditional formulas based on form answers (yes, no checkboxes) Sarah Excel Discussion (Misc queries) 2 May 30th 07 03:27 PM
Excel Appearance Anonymous Excel Discussion (Misc queries) 2 September 19th 06 09:22 PM
conditional Formatting using checkboxes macquarl Excel Discussion (Misc queries) 1 December 6th 05 08:55 PM
From Excel to VBA Chart appearance Mark Stephens Charts and Charting in Excel 1 May 10th 05 09:48 PM


All times are GMT +1. The time now is 02:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"