View Single Post
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

My bet is that it's a typo.

Worksheets("Sheets1").cmbList.AddItem (roomName)

Is the worksheet really named SheetS1 (with that extra S near the end)?

And I'd be hesitant to use a variable named Item. It's used in VBA, too. And
it may not confuse excel, but it sure can confuse me. (I also don't like single
character variables--but that's a personal preference.) And I like declaring my
variables, too.



Option Explicit
Sub testme01()

Dim myStr As String
Dim iCtr As Long
Dim RoomName As String

For iCtr = 1 To 6
myStr = "I" & iCtr
RoomName = Worksheets("Sheet1").Range(myStr).Value
Worksheets("Sheet1").cmblist.AddItem RoomName
'MsgBox RoomName
Next iCtr

End Sub


Kiran wrote:

For I = 1 To 6
Dim Item As String
Item = "I" & CStr(I)

roomName = Worksheets("Sheet1").Range(Item).Value
Worksheets("Sheets1").cmbList.AddItem (roomName)
MsgBox (roomName)
Next

I dont know why this piece of code is throwsing the error. If the line
Worksheets("Sheets1").cmbList.AddItem (roomName) is commented out, then the
msg box shows all the 6 items there. Which tells me there is some problem
with this line of code(combo box). Is there a property that needs to be set
for combo box's?Please help... Thnx


--

Dave Peterson