PC Review


Reply
Thread Tools Rate Thread

Array to Range assignments behave different going horizontally and vertically

 
 
gimme_this_gimme_that@yahoo.com
Guest
Posts: n/a
 
      28th May 2007
The following sub creates

1
1
1

Sub test()
Dim b As Workbook
Dim s As Worksheet
Set b = ThisWorkbook
Set s = b.Sheets("Sheet1")
s.Activate
Dim v
v = Array(1, 4, 6)
Dim r As Range
Set r = s.Range(s.Cells(1, 1), s.Cells(3, 1))
r.Value = v
End Sub

When I change the r assignment to

Set r = s.Range(s.Cells1,1),s.Cells(1,3)

I get

1 4 6

What is the logic in Excel that makes it treat horizontal assignments
different from vertical ones?

Thanks.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?=
Guest
Posts: n/a
 
      29th May 2007
What is it you want to do and we can help.

"(E-Mail Removed)" wrote:

> The following sub creates
>
> 1
> 1
> 1
>
> Sub test()
> Dim b As Workbook
> Dim s As Worksheet
> Set b = ThisWorkbook
> Set s = b.Sheets("Sheet1")
> s.Activate
> Dim v
> v = Array(1, 4, 6)
> Dim r As Range
> Set r = s.Range(s.Cells(1, 1), s.Cells(3, 1))
> r.Value = v
> End Sub
>
> When I change the r assignment to
>
> Set r = s.Range(s.Cells1,1),s.Cells(1,3)
>
> I get
>
> 1 4 6
>
> What is the logic in Excel that makes it treat horizontal assignments
> different from vertical ones?
>
> Thanks.
>
>

 
Reply With Quote
 
Alan Beban
Guest
Posts: n/a
 
      29th May 2007
In the first case you are trying to enter a horizontal array into a
vertical range.

Alan Beban
(E-Mail Removed) wrote:
> The following sub creates
>
> 1
> 1
> 1
>
> Sub test()
> Dim b As Workbook
> Dim s As Worksheet
> Set b = ThisWorkbook
> Set s = b.Sheets("Sheet1")
> s.Activate
> Dim v
> v = Array(1, 4, 6)
> Dim r As Range
> Set r = s.Range(s.Cells(1, 1), s.Cells(3, 1))
> r.Value = v
> End Sub
>
> When I change the r assignment to
>
> Set r = s.Range(s.Cells1,1),s.Cells(1,3)
>
> I get
>
> 1 4 6
>
> What is the logic in Excel that makes it treat horizontal assignments
> different from vertical ones?
>
> Thanks.
>

 
Reply With Quote
 
gimme_this_gimme_that@yahoo.com
Guest
Posts: n/a
 
      29th May 2007
Thanks Alan,

Is it possible to create a vertical array?

On May 28, 5:47 pm, Alan Beban <unavailable> wrote:
> In the first case you are trying to enter a horizontal array into a
> vertical range.
>
> Alan Beban


 
Reply With Quote
 
JE McGimpsey
Guest
Posts: n/a
 
      29th May 2007
One way:

r.Value = Application.Transpose(v)

In article <(E-Mail Removed)>,
"(E-Mail Removed)" <(E-Mail Removed)>
wrote:

> Is it possible to create a vertical array?

 
Reply With Quote
 
Alan Beban
Guest
Posts: n/a
 
      29th May 2007
For me this throws an "Object required" error.

r = Application.Transpose(v) works

Alan Beban

JE McGimpsey wrote:
> One way:
>
> r.Value = Application.Transpose(v)
>
> In article <(E-Mail Removed)>,
> "(E-Mail Removed)" <(E-Mail Removed)>
> wrote:
>
>> Is it possible to create a vertical array?

 
Reply With Quote
 
JE McGimpsey
Guest
Posts: n/a
 
      29th May 2007
Hmm... what version of XL?

Is r not defined as an object, or is it Application?

r.Value = Application.Transpose(v)

works fine for me in XL04 when plugged into the OP's code.

In article <(E-Mail Removed)>,
Alan Beban <unavailable> wrote:

> For me this throws an "Object required" error.
>
> r = Application.Transpose(v) works
>
> Alan Beban
>
> JE McGimpsey wrote:
> > One way:
> >
> > r.Value = Application.Transpose(v)
> >
> > In article <(E-Mail Removed)>,
> > "(E-Mail Removed)" <(E-Mail Removed)>
> > wrote:
> >
> >> Is it possible to create a vertical array?

 
Reply With Quote
 
Alan Beban
Guest
Posts: n/a
 
      30th May 2007
xl2002. I ran

Sub abtest3()
v = Array(2, 4, 8)
s = Array(2, 8, 11)
r.Value = Application.Transpose(v)
'Range("a1:a3") = Application.Transpose(v)
'Range("b1:b3") = Application.Transpose(s)
End Sub

If I insert Dim r as Range or Dim r as Object at the begining I get the
"Object variable or With block variable not set" error

Alan Beban

JE McGimpsey wrote:
> Hmm... what version of XL?
>
> Is r not defined as an object, or is it Application?
>
> r.Value = Application.Transpose(v)
>
> works fine for me in XL04 when plugged into the OP's code.
>
> In article <(E-Mail Removed)>,
> Alan Beban <unavailable> wrote:
>
>> For me this throws an "Object required" error.
>>
>> r = Application.Transpose(v) works
>>
>> Alan Beban
>>
>> JE McGimpsey wrote:
>>> One way:
>>>
>>> r.Value = Application.Transpose(v)
>>>
>>> In article <(E-Mail Removed)>,
>>> "(E-Mail Removed)" <(E-Mail Removed)>
>>> wrote:
>>>
>>>> Is it possible to create a vertical array?

 
Reply With Quote
 
JE McGimpsey
Guest
Posts: n/a
 
      30th May 2007
Not sure I understand what you're doing...

Your code doesn't Dim or Set r, so I would expect an "Object required"
error (assuming no Option Explicit, which I always use).

I'd expect the "Object variable...not set" error if you inserted either
Dim statement, since, again, the code doesn't actually Set r to a range.

The OP's code set the r range object variable to a range of cells before
trying to assign the variant containing the array to r.Value:

> Sub test()
> Dim b As Workbook
> Dim s As Worksheet
> Set b = ThisWorkbook
> Set s = b.Sheets("Sheet1")
> s.Activate
> Dim v
> v = Array(1, 4, 6)
> Dim r As Range
> Set r = s.Range(s.Cells(1, 1), s.Cells(3, 1))
> r.Value = v
> End Sub


I was giving a suggestion only for the line after that...



In article <evN#(E-Mail Removed)>,
Alan Beban <unavailable> wrote:

> xl2002. I ran
>
> Sub abtest3()
> v = Array(2, 4, 8)
> s = Array(2, 8, 11)
> r.Value = Application.Transpose(v)
> 'Range("a1:a3") = Application.Transpose(v)
> 'Range("b1:b3") = Application.Transpose(s)
> End Sub
>
> If I insert Dim r as Range or Dim r as Object at the begining I get the
> "Object variable or With block variable not set" error
>
> Alan Beban

 
Reply With Quote
 
Alan Beban
Guest
Posts: n/a
 
      31st May 2007
I was responding to the Op's question in his posting on 5/28/07 at 5:59:

"Is it possible to create a vertical array?" to which I thought you were
responding.

Wouldn't your code, then, load a vertical range rather than create a
vertical array?

Alan Beban

JE McGimpsey wrote:
> Not sure I understand what you're doing...
>
> Your code doesn't Dim or Set r, so I would expect an "Object required"
> error (assuming no Option Explicit, which I always use).
>
> I'd expect the "Object variable...not set" error if you inserted either
> Dim statement, since, again, the code doesn't actually Set r to a range.
>
> The OP's code set the r range object variable to a range of cells before
> trying to assign the variant containing the array to r.Value:
>
>> Sub test()
>> Dim b As Workbook
>> Dim s As Worksheet
>> Set b = ThisWorkbook
>> Set s = b.Sheets("Sheet1")
>> s.Activate
>> Dim v
>> v = Array(1, 4, 6)
>> Dim r As Range
>> Set r = s.Range(s.Cells(1, 1), s.Cells(3, 1))
>> r.Value = v
>> End Sub

>
> I was giving a suggestion only for the line after that...
>
>
>
> In article <evN#(E-Mail Removed)>,
> Alan Beban <unavailable> wrote:
>
>> xl2002. I ran
>>
>> Sub abtest3()
>> v = Array(2, 4, 8)
>> s = Array(2, 8, 11)
>> r.Value = Application.Transpose(v)
>> 'Range("a1:a3") = Application.Transpose(v)
>> 'Range("b1:b3") = Application.Transpose(s)
>> End Sub
>>
>> If I insert Dim r as Range or Dim r as Object at the begining I get the
>> "Object variable or With block variable not set" error
>>
>> Alan Beban

 
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
Looking up for value vertically and horizontally simultaneously Sanjeev Raghavan Microsoft Excel Worksheet Functions 1 6th Mar 2010 12:59 PM
How do I set up a page horizontally vs vertically programmer Microsoft Word Document Management 2 5th Sep 2008 12:21 AM
How can I type vertically instead of horizontally? Photo Jon Microsoft Word Document Management 2 14th Jan 2008 01:20 AM
Freezing both horizontally and vertically AA Arens Microsoft Excel Discussion 3 26th Aug 2006 02:08 PM
Tile Horizontally/Vertically Johnie Karr Windows XP General 0 27th Nov 2003 06:45 PM


Features
 

Advertising
 

Newsgroups
 


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