PC Review


Reply
Thread Tools Rate Thread

AddItem to Worksheet ComboBox

 
 
Paul D Byrne
Guest
Posts: n/a
 
      24th Jul 2008
Hi,

I am developing a program to read a matrix of comments and then add an item
to a combo box on a worksheet. In a sheet labeled 'DataHandler' I have 5
ranges "Comment_Step" which holds the step reference eg 1.1, 1.2, 2.3 etc,
then another range "Comment_Test" which holds a list of comments that apply
to the steps in the first range. In a worksheet titled "OI - Test" I have a
number of comboboxes using the naming convention "Test1pt1", "Test1pt2",
"Test1pt3".

Using a vba in the worksheet_activate event I am trying to loop through each
combobox and add the relevant items to each. Below is the code.

For some reason the additem keeps throwing up error 438, "Object doesn't
support this property or method". I am obviously not setting the object
reference correctly or have a property set incorrectly, as the additem method
doesn't appear in the objCombo reference. Any clues as to how to get this
going? Below is the code

Private Sub Worksheet_Activate()

Dim strSheetName As String
Dim strCommentName As String
Dim strStep As String
Dim strStepConversion As String

Dim intStepStart As Integer
Dim intStepPt As Integer
Dim sngStep As Single
Dim i, j As Integer

Dim shtActive As Worksheet
Dim oleCombo As OLEObject

Dim shtHandler As Worksheet
Dim rngStep As Range
Dim rngList As Range

Set shtActive = ThisWorkbook.ActiveSheet
strSheetName = Trim(Mid(shtActive.Name, 6, Len(shtActive.Name) - 5))
strCommentName = "Comment_" & strSheetName

For i = 1 To shtActive.OLEObjects.Count

Set oleCombo = shtActive.OLEObjects(1)
oleCombo.Select
strStep = Mid(oleCombo.Name, Len(strSheetName) + 1,
Len(oleCombo.Name) - Len(strSheetName))
intStepPt = InStr(1, strStep, "pt", vbTextCompare)
strStepConversion = Left(strStep, intStepPt - 1) & "." &
Mid(strStep, intStepPt + 2, Len(strStep) - intStepPt + 1)
sngStep = CSng(strStepConversion)
Debug.Print sngStep

Set shtHandler = ThisWorkbook.Sheets("DataHandler")
Set rngStep = shtHandler.Range("Comment_Step")
Set rngList = shtHandler.Range(strCommentName)

For j = 2 To rngStep.Rows.Count

If rngStep.Cells(j, 1).Value = sngStep Then

If rngList.Cells(j, 1).Value <> "" Then

oleCombo.AddItem rngList.Cells(j, 1).Value

Else
End If

Else
End If

Next

Next

End Sub


cheers,
--
Paul Byrne
 
Reply With Quote
 
 
 
 
RyanH
Guest
Posts: n/a
 
      24th Jul 2008
Do you have anyother controls on the worksheet? I see in your loop you count
all ActiveX controls. If you have a checkbox in your worksheet for example,
you will get an error.
--
Cheers,
Ryan


"Paul D Byrne" wrote:

> Hi,
>
> I am developing a program to read a matrix of comments and then add an item
> to a combo box on a worksheet. In a sheet labeled 'DataHandler' I have 5
> ranges "Comment_Step" which holds the step reference eg 1.1, 1.2, 2.3 etc,
> then another range "Comment_Test" which holds a list of comments that apply
> to the steps in the first range. In a worksheet titled "OI - Test" I have a
> number of comboboxes using the naming convention "Test1pt1", "Test1pt2",
> "Test1pt3".
>
> Using a vba in the worksheet_activate event I am trying to loop through each
> combobox and add the relevant items to each. Below is the code.
>
> For some reason the additem keeps throwing up error 438, "Object doesn't
> support this property or method". I am obviously not setting the object
> reference correctly or have a property set incorrectly, as the additem method
> doesn't appear in the objCombo reference. Any clues as to how to get this
> going? Below is the code
>
> Private Sub Worksheet_Activate()
>
> Dim strSheetName As String
> Dim strCommentName As String
> Dim strStep As String
> Dim strStepConversion As String
>
> Dim intStepStart As Integer
> Dim intStepPt As Integer
> Dim sngStep As Single
> Dim i, j As Integer
>
> Dim shtActive As Worksheet
> Dim oleCombo As OLEObject
>
> Dim shtHandler As Worksheet
> Dim rngStep As Range
> Dim rngList As Range
>
> Set shtActive = ThisWorkbook.ActiveSheet
> strSheetName = Trim(Mid(shtActive.Name, 6, Len(shtActive.Name) - 5))
> strCommentName = "Comment_" & strSheetName
>
> For i = 1 To shtActive.OLEObjects.Count
>
> Set oleCombo = shtActive.OLEObjects(1)
> oleCombo.Select
> strStep = Mid(oleCombo.Name, Len(strSheetName) + 1,
> Len(oleCombo.Name) - Len(strSheetName))
> intStepPt = InStr(1, strStep, "pt", vbTextCompare)
> strStepConversion = Left(strStep, intStepPt - 1) & "." &
> Mid(strStep, intStepPt + 2, Len(strStep) - intStepPt + 1)
> sngStep = CSng(strStepConversion)
> Debug.Print sngStep
>
> Set shtHandler = ThisWorkbook.Sheets("DataHandler")
> Set rngStep = shtHandler.Range("Comment_Step")
> Set rngList = shtHandler.Range(strCommentName)
>
> For j = 2 To rngStep.Rows.Count
>
> If rngStep.Cells(j, 1).Value = sngStep Then
>
> If rngList.Cells(j, 1).Value <> "" Then
>
> oleCombo.AddItem rngList.Cells(j, 1).Value
>
> Else
> End If
>
> Else
> End If
>
> Next
>
> Next
>
> End Sub
>
>
> cheers,
> --
> Paul Byrne

 
Reply With Quote
 
Paul D Byrne
Guest
Posts: n/a
 
      25th Jul 2008
Hi Ryan,

No - only the comboboxes.

thanks,

Paul B.
--
Paul Byrne


"RyanH" wrote:

> Do you have anyother controls on the worksheet? I see in your loop you count
> all ActiveX controls. If you have a checkbox in your worksheet for example,
> you will get an error.
> --
> Cheers,
> Ryan
>
>
> "Paul D Byrne" wrote:
>
> > Hi,
> >
> > I am developing a program to read a matrix of comments and then add an item
> > to a combo box on a worksheet. In a sheet labeled 'DataHandler' I have 5
> > ranges "Comment_Step" which holds the step reference eg 1.1, 1.2, 2.3 etc,
> > then another range "Comment_Test" which holds a list of comments that apply
> > to the steps in the first range. In a worksheet titled "OI - Test" I have a
> > number of comboboxes using the naming convention "Test1pt1", "Test1pt2",
> > "Test1pt3".
> >
> > Using a vba in the worksheet_activate event I am trying to loop through each
> > combobox and add the relevant items to each. Below is the code.
> >
> > For some reason the additem keeps throwing up error 438, "Object doesn't
> > support this property or method". I am obviously not setting the object
> > reference correctly or have a property set incorrectly, as the additem method
> > doesn't appear in the objCombo reference. Any clues as to how to get this
> > going? Below is the code
> >
> > Private Sub Worksheet_Activate()
> >
> > Dim strSheetName As String
> > Dim strCommentName As String
> > Dim strStep As String
> > Dim strStepConversion As String
> >
> > Dim intStepStart As Integer
> > Dim intStepPt As Integer
> > Dim sngStep As Single
> > Dim i, j As Integer
> >
> > Dim shtActive As Worksheet
> > Dim oleCombo As OLEObject
> >
> > Dim shtHandler As Worksheet
> > Dim rngStep As Range
> > Dim rngList As Range
> >
> > Set shtActive = ThisWorkbook.ActiveSheet
> > strSheetName = Trim(Mid(shtActive.Name, 6, Len(shtActive.Name) - 5))
> > strCommentName = "Comment_" & strSheetName
> >
> > For i = 1 To shtActive.OLEObjects.Count
> >
> > Set oleCombo = shtActive.OLEObjects(1)
> > oleCombo.Select
> > strStep = Mid(oleCombo.Name, Len(strSheetName) + 1,
> > Len(oleCombo.Name) - Len(strSheetName))
> > intStepPt = InStr(1, strStep, "pt", vbTextCompare)
> > strStepConversion = Left(strStep, intStepPt - 1) & "." &
> > Mid(strStep, intStepPt + 2, Len(strStep) - intStepPt + 1)
> > sngStep = CSng(strStepConversion)
> > Debug.Print sngStep
> >
> > Set shtHandler = ThisWorkbook.Sheets("DataHandler")
> > Set rngStep = shtHandler.Range("Comment_Step")
> > Set rngList = shtHandler.Range(strCommentName)
> >
> > For j = 2 To rngStep.Rows.Count
> >
> > If rngStep.Cells(j, 1).Value = sngStep Then
> >
> > If rngList.Cells(j, 1).Value <> "" Then
> >
> > oleCombo.AddItem rngList.Cells(j, 1).Value
> >
> > Else
> > End If
> >
> > Else
> > End If
> >
> > Next
> >
> > Next
> >
> > End Sub
> >
> >
> > cheers,
> > --
> > Paul Byrne

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combobox.additem (No Repeats) PaulW Microsoft Excel Programming 3 9th Dec 2007 06:13 PM
additem to combobox with an array jocke Microsoft Excel Misc 2 29th Sep 2005 07:56 PM
combobox additem masterphilch Microsoft Excel Programming 2 25th Oct 2004 11:04 PM
RE: AddItem Method - Combobox value Todd Huttenstine Microsoft Excel Programming 2 21st Apr 2004 05:13 PM
additem to a combobox from other excel worksheet gelu Microsoft Excel Programming 1 1st Mar 2004 04:36 PM


Features
 

Advertising
 

Newsgroups
 


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