ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using IF, Then with rowsource? (https://www.excelbanter.com/excel-programming/293919-using-if-then-rowsource.html)

CAA[_23_]

Using IF, Then with rowsource?
 
Does anybody know why i can't do this

If ShN 4 And ShN < 9 Then
shHeight1.Enabled = False
shHeight1.BackColor = &HA49597
ShHang1.RowSource = "Sheet1!B50:B56"
Else
shHeight1.Enabled = False
shHeight1.BackColor = &HF9F8EC
ShHang1.RowSource = Sheets("Window Styles").Range("C50:C57")
End If

Hope somebody can shed some light for me.
Thanks
CA

--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

Using IF, Then with rowsource?
 
You don't say what the problem is. If it is this line

ShHang1.RowSource = Sheets("Window Styles").Range("C50:C57")

try

ShHang1.RowSource = "'" & Sheets("Window Styles").Name & "'!" &
Sheets("Window Styles").Range("C50:C57").Address

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"CAA " wrote in message
...
Does anybody know why i can't do this

If ShN 4 And ShN < 9 Then
shHeight1.Enabled = False
shHeight1.BackColor = &HA49597
ShHang1.RowSource = "Sheet1!B50:B56"
Else
shHeight1.Enabled = False
shHeight1.BackColor = &HF9F8EC
ShHang1.RowSource = Sheets("Window Styles").Range("C50:C57")
End If

Hope somebody can shed some light for me.
Thanks
CAA


---
Message posted from http://www.ExcelForum.com/




CAA[_24_]

Using IF, Then with rowsource?
 
Sorry Bob
However a guru like yourself can spot these problems withou
explanation ;-)

The problem was it didn't populate my combobox.
I tried your piece of code and still nothing, so I trimmed out th
first bit and then realised that an erlier attempt only needed th
.Address at the end. Which after trimming yours was exactly what
needed.

I need to read more about the references cells, previously I had gotte
away with just "Sheet1!B50:B56" but had never ttried within an i
statement to set it at runtime, quirky stuff.

Thanks alot for your help, my day has just become lighter.
CA

--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

Using IF, Then with rowsource?
 
The Rowsource is a string property and you were setting it to a range. This
part, Sheet1!B50:B56" , is a nice simple string, when using a reference to
another part of a worksheet it is not so obvious is it.

Anyway, glad you are sorted now.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"CAA " wrote in message
...
Sorry Bob
However a guru like yourself can spot these problems without
explanation ;-)

The problem was it didn't populate my combobox.
I tried your piece of code and still nothing, so I trimmed out the
first bit and then realised that an erlier attempt only needed the
Address at the end. Which after trimming yours was exactly what I
needed.

I need to read more about the references cells, previously I had gotten
away with just "Sheet1!B50:B56" but had never ttried within an if
statement to set it at runtime, quirky stuff.

Thanks alot for your help, my day has just become lighter.
CAA


---
Message posted from http://www.ExcelForum.com/




Dave Peterson[_3_]

Using IF, Then with rowsource?
 
I find this style easier to type and read:

ShHang1.RowSource _
= Sheets("Window Styles").Range("C50:C57").address(external:=true)

Bob Phillips wrote:

You don't say what the problem is. If it is this line

ShHang1.RowSource = Sheets("Window Styles").Range("C50:C57")

try

ShHang1.RowSource = "'" & Sheets("Window Styles").Name & "'!" &
Sheets("Window Styles").Range("C50:C57").Address

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"CAA " wrote in message
...
Does anybody know why i can't do this

If ShN 4 And ShN < 9 Then
shHeight1.Enabled = False
shHeight1.BackColor = &HA49597
ShHang1.RowSource = "Sheet1!B50:B56"
Else
shHeight1.Enabled = False
shHeight1.BackColor = &HF9F8EC
ShHang1.RowSource = Sheets("Window Styles").Range("C50:C57")
End If

Hope somebody can shed some light for me.
Thanks
CAA


---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson


CAA[_25_]

Using IF, Then with rowsource?
 
Cheers Dave

That's nearly exactly as i've put it, however i don't have a clue wha
the (external = true) is for, I looked it up and found it mean
external referance.
I don't know what that means for excel, I use Autocad and an externa
referance is part of the drawing that is a copy of another drawing
when the other is updated then the changes are reflected in you
current drawing, is this similar for Excel?


CA

--
Message posted from http://www.ExcelForum.com


Dave Peterson[_3_]

Using IF, Then with rowsource?
 
Try this:

with activesheet
msgbox .range("a1").address
msgbox .range("a1").address(0,0)
msgbox .range("a1").address(external:=true)
end with

And you'll see what it does.



"CAA <" wrote:

Cheers Dave

That's nearly exactly as i've put it, however i don't have a clue what
the (external = true) is for, I looked it up and found it means
external referance.
I don't know what that means for excel, I use Autocad and an external
referance is part of the drawing that is a copy of another drawing,
when the other is updated then the changes are reflected in your
current drawing, is this similar for Excel?

CAA

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson


Tom Ogilvy

Using IF, Then with rowsource?
 
Address returns a string showing the address of the range. The optional
arguments ajdust the appearance of that address.

by default it is

With Workbooks("Book1.xls")
Set rng = .Worksheets("Sheet5").Range("B9:C12")
End With

rng.Address would return
$B$9:$C$12

rng.Address(external:=True) would return
[Book1.xls]Sheet5!$B$9:$C$12

So External really means fully qualified - the thought being that you
wouldn't need that information unless the reference was to a workbook
external to the current one.

--
Regards,
Tom Ogilvy


"CAA " wrote in message
...
Cheers Dave

That's nearly exactly as i've put it, however i don't have a clue what
the (external = true) is for, I looked it up and found it means
external referance.
I don't know what that means for excel, I use Autocad and an external
referance is part of the drawing that is a copy of another drawing,
when the other is updated then the changes are reflected in your
current drawing, is this similar for Excel?


CAA


---
Message posted from http://www.ExcelForum.com/




CAA[_26_]

Using IF, Then with rowsource?
 
Well, I've learnt quite a bit And all is very handy stuff

As it turned out Bob gave me the right answer for my situation th
fisrt time round.
I had trimmed off the first part and because my form has model=Fals
whenever i changed worksheets the combobox rowsource changed.
Thanks alot for the help guys
CA

--
Message posted from http://www.ExcelForum.com



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com