Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA fill a userform combo box RowSource with a string variable? 1

Status
Not open for further replies.

knifey

Technical User
Nov 14, 2006
180
GB
Hi,
I have a combo box on a userform that needs to be filled from a different range each time,
The code I have below looks like it should work fine. But it errors on the strRowSource = line. Please can anyone offer any advice on the syntax?
Thanks
K

strRowSource = meFileName & "=!" & Sheets("LOV").Range("$B$" & firstRow & ":$B$" & (firstRow + numWords))
'strRowSource = wb4 & "!" & Sheets("LOV").Range("$B$" & firstRow & ":$B$" & (firstRow + numWords))
'strRowSource = meFileName & "!" & Sheets("LOV").Range("$B$" & firstRow & ":$B$" & (firstRow + numWords))

With frmChooseMonth.cmbChooseMonth
'Clear old ListBox RowSource
.RowSource = vbNullString
'Parse new one
.RowSource = strRowSource
End With
 
Code:
strRowSource = meFileName & [b][red]"!"[/red][/b] & Sheets("LOV").Range("$B$" & firstRow & ":$B$" & (firstRow + numWords))

I think that = is throwing you off?
 
Hi Gruu,
I ran your code but it comes up with a run tim error 13, type mismatch.
Any ideas on what could be causing this?
Thanks,
K
 
Post all of the code that this pertains to?
I see the problem, but need to see the whole code to direct you to the solution.

 

Isn't the result something like...
[tt]
Sheet!A2:A36
[/tt]
If so...
Code:
with Sheets("LOV")
  strRowSource = .Name & "!" & .Range("$B$" & firstRow & ":$B$" & (firstRow + numWords)).Address
end with




Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I'd try this:
Code:
strRowSource = "LOV!B" & firstRow & ":B" & (firstRow + numWords)


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV,
I just saw another post you answered and went with that code (more or less the same):

strRowSource = meFileName & "!" & Sheets("LOV").Range("$B$" & firstRow & ":$B$" & (firstRow + numWords)).Address

Works perfectly,
Cheers,
K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top