Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Dynamically add Checkboxes to worksheet columns

All,

I have a VBA function that populates a worksheet with data. I'd like to
dynamically add a checkbox to the first column of each new row that is
added. I want the checkbox to be inserted and remain within the cell. The
number of rows to be added is not known ahead of time. What's the best way
to accomplish this?

Thanks,

Mark D'Agosta



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 179
Default Dynamically add Checkboxes to worksheet columns

Mark

Here's a sub I use to but checkboxes next to a QueryTable. Maybe you can
adapt it to your situation.

Sub UpdateList()

Dim sh As Worksheet
Dim cell As Range
Dim Rng As Range
Dim chbx As OLEObject

Set sh = ThisWorkbook.Worksheets("sheet1")

For Each chbx In sh.OLEObjects
chbx.Delete
Next chbx

sh.Columns(1).ClearContents

sh.QueryTables(1).Refresh False

Set Rng = sh.Range("b2", sh.Range("b2").End(xlDown))

sh.Range("d2:h2").Columns.AutoFit
sh.Range("a1").Rows.AutoFit
sh.Range("j1").ColumnWidth = 2

For Each cell In Rng.Cells
cell.RowHeight = 15
With sh.OLEObjects.Add("forms.checkbox.1")
.Left = cell.Offset(0, -1).Left
.Top = cell.Offset(0, -1).Top
.Width = cell.Offset(0, -1).Width
.LinkedCell = cell.Offset(0, -1).Address
.Object.Value = False
.Object.Caption = ""
End With
Next cell

Set sh = Nothing
Set cell = Nothing
Set Rng = Nothing
Set chbx = Nothing

End Sub

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Mark D'Agosta" wrote in message
...
All,

I have a VBA function that populates a worksheet with data. I'd like to
dynamically add a checkbox to the first column of each new row that is
added. I want the checkbox to be inserted and remain within the cell.

The
number of rows to be added is not known ahead of time. What's the best

way
to accomplish this?

Thanks,

Mark D'Agosta





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
Dynamically setting worksheet tab colors John Excel Worksheet Functions 4 January 29th 09 06:55 PM
Creating a Dynamically Linked Worksheet BRob Excel Worksheet Functions 0 June 11th 08 09:55 AM
Sum columns dynamically Delboy Excel Worksheet Functions 1 July 28th 06 03:33 PM
Can't dynamically add withevents OptionButton to worksheet onedaywhen Excel Programming 6 August 27th 03 09:11 AM
How to code event for dynamically generated checkboxes Chong Moua Excel Programming 0 July 9th 03 08:18 PM


All times are GMT +1. The time now is 02:54 PM.

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"