Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Referring to ranges as Cell, Range, and variables

I have been experimenting with the whole Cells([whatever, whatever]),
Range(Whatever, whatever), using variables that are ranges, etc., and I
swear every time I think I have figured out how to refer to things, I get
the error about type mismatch. I mean really.

Can anyone tell me how to get this to work:

Worksheets("MySheet").Range("A65536").End(xlUp).Of fset(1, 0).Address ,
("A" & UBound(MyArray) + 1) =
Application.WorksheetFunction.Transpose(MyArray)

This is supposed to find the first blank cell in A, set the range from there
to the number of elements in my array down, then put in my array values. I
can debug.print the 1st address, printing ("A" & UBound(MyArray) + 1) IS
giving me "A9" (there are 8 elements in my array), so that's working, and I
can print the elements in the array. I set a range and filled it EXACTLY
like this before, except for that I was using Range("A1:A" & UBound(MyArray)
+ 1), and that worked perfectly. This seems so slightly different I can't
figure out whay I'd get type mismatch.

As long as I'm talking about it, does anyone know how to paste an array's
values by just selecting the first cell you want? In Excel, if you have
ranges/values in the clipboard, you can click just one cell and paste; is
there a way in vba to just click one cell and transpose your array
successfully, besides looping through every element and offsetting every
time?

Thanks again. I know I'm posting a lot, but believe me, I'm spending hours
on everything I can't quite get. And I found out how to do some great stuff
I never knew about before, but unfortunately none of it applies to what I'm
doing.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 420
Default Referring to ranges as Cell, Range, and variables

I'd break it down into smaller pieces...

Option Explicit
Sub testme()

Dim myArray As Variant
Dim DestCell As Range

myArray = Array("a", "b", "c", "d")

With Worksheets("mySheet")
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With

DestCell.Resize(UBound(myArray) - LBound(myArray) + 1, 1).Value _
= Application.Transpose(myArray)

End Sub



On 10/15/2010 02:20, CompleteNewb wrote:
I have been experimenting with the whole Cells([whatever, whatever]),
Range(Whatever, whatever), using variables that are ranges, etc., and I swear
every time I think I have figured out how to refer to things, I get the error
about type mismatch. I mean really.

Can anyone tell me how to get this to work:

Worksheets("MySheet").Range("A65536").End(xlUp).Of fset(1, 0).Address , ("A" &
UBound(MyArray) + 1) = Application.WorksheetFunction.Transpose(MyArray)

This is supposed to find the first blank cell in A, set the range from there to
the number of elements in my array down, then put in my array values. I can
debug.print the 1st address, printing ("A" & UBound(MyArray) + 1) IS giving me
"A9" (there are 8 elements in my array), so that's working, and I can print the
elements in the array. I set a range and filled it EXACTLY like this before,
except for that I was using Range("A1:A" & UBound(MyArray) + 1), and that worked
perfectly. This seems so slightly different I can't figure out whay I'd get type
mismatch.

As long as I'm talking about it, does anyone know how to paste an array's values
by just selecting the first cell you want? In Excel, if you have ranges/values
in the clipboard, you can click just one cell and paste; is there a way in vba
to just click one cell and transpose your array successfully, besides looping
through every element and offsetting every time?

Thanks again. I know I'm posting a lot, but believe me, I'm spending hours on
everything I can't quite get. And I found out how to do some great stuff I never
knew about before, but unfortunately none of it applies to what I'm doing.


--
Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default Referring to ranges as Cell, Range, and variables

A9 is a string not a range and you can't use Range like that anyway.

If you want to create a range using 2 range references you need
something like this.

Worksheets("MySheet").Range(Worksheets("MySheet"). Range("A" &
Rows.Count).End(xlUp).Offset(1).Address,
Worksheets("MySheet").Range("A" & UBound(Myarray) + 1).Address)

Rather unwieldy.:)

Why not try using some other method, perhaps Resize or Offset?

Which to use and how to use them depends on what range you actually
want to refer to is.

It might also be worth splitting the code up a bit and creating a
range reference:

addr1 = Worksheets("MySheet").Range("A" &
Rows.Count).End(xlUp).Offset(1).Address

addr2 = Worksheets("MySheet").Range("A" & UBound(Myarray) + 1).Address

Set rng = Worksheets("MySheet").Range(addr1, addr2)
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Referring to ranges as Cell, Range, and variables

Dave, thanks for trying to help, but I'm getting invalid use of Resize error
when trying to do below; in case it was the way I was referring to my ranges
as variables, or cells, or some other incorrect way of doing things, I tried
doing exactly what's below, and still got invalid use of resize (even though
the vba editor was putting up the autocomplete help as I was putting
"resize" in.


"Dave Peterson" wrote in message
...
I'd break it down into smaller pieces...

Option Explicit
Sub testme()

Dim myArray As Variant
Dim DestCell As Range

myArray = Array("a", "b", "c", "d")

With Worksheets("mySheet")
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With

DestCell.Resize(UBound(myArray) - LBound(myArray) + 1, 1).Value _
= Application.Transpose(myArray)

End Sub



On 10/15/2010 02:20, CompleteNewb wrote:
I have been experimenting with the whole Cells([whatever, whatever]),
Range(Whatever, whatever), using variables that are ranges, etc., and I
swear
every time I think I have figured out how to refer to things, I get the
error
about type mismatch. I mean really.

Can anyone tell me how to get this to work:

Worksheets("MySheet").Range("A65536").End(xlUp).Of fset(1, 0).Address ,
("A" &
UBound(MyArray) + 1) = Application.WorksheetFunction.Transpose(MyArray)

This is supposed to find the first blank cell in A, set the range from
there to
the number of elements in my array down, then put in my array values. I
can
debug.print the 1st address, printing ("A" & UBound(MyArray) + 1) IS
giving me
"A9" (there are 8 elements in my array), so that's working, and I can
print the
elements in the array. I set a range and filled it EXACTLY like this
before,
except for that I was using Range("A1:A" & UBound(MyArray) + 1), and that
worked
perfectly. This seems so slightly different I can't figure out whay I'd
get type
mismatch.

As long as I'm talking about it, does anyone know how to paste an array's
values
by just selecting the first cell you want? In Excel, if you have
ranges/values
in the clipboard, you can click just one cell and paste; is there a way
in vba
to just click one cell and transpose your array successfully, besides
looping
through every element and offsetting every time?

Thanks again. I know I'm posting a lot, but believe me, I'm spending
hours on
everything I can't quite get. And I found out how to do some great stuff
I never
knew about before, but unfortunately none of it applies to what I'm
doing.


--
Dave Peterson


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 621
Default Referring to ranges as Cell, Range, and variables

Dave's code fills a,b,c,d into the first 4 blank cells below last cell in column
A

Works fine for me.

Try copy/pasting the code rather than typing.


Gord Dibben MS Excel MVP


On Sun, 17 Oct 2010 13:52:25 -0400, "CompleteNewb"
wrote:

Dave, thanks for trying to help, but I'm getting invalid use of Resize error
when trying to do below; in case it was the way I was referring to my ranges
as variables, or cells, or some other incorrect way of doing things, I tried
doing exactly what's below, and still got invalid use of resize (even though
the vba editor was putting up the autocomplete help as I was putting
"resize" in.


"Dave Peterson" wrote in message
...
I'd break it down into smaller pieces...

Option Explicit
Sub testme()

Dim myArray As Variant
Dim DestCell As Range

myArray = Array("a", "b", "c", "d")

With Worksheets("mySheet")
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With

DestCell.Resize(UBound(myArray) - LBound(myArray) + 1, 1).Value _
= Application.Transpose(myArray)

End Sub



On 10/15/2010 02:20, CompleteNewb wrote:
I have been experimenting with the whole Cells([whatever, whatever]),
Range(Whatever, whatever), using variables that are ranges, etc., and I
swear
every time I think I have figured out how to refer to things, I get the
error
about type mismatch. I mean really.

Can anyone tell me how to get this to work:

Worksheets("MySheet").Range("A65536").End(xlUp).Of fset(1, 0).Address ,
("A" &
UBound(MyArray) + 1) = Application.WorksheetFunction.Transpose(MyArray)

This is supposed to find the first blank cell in A, set the range from
there to
the number of elements in my array down, then put in my array values. I
can
debug.print the 1st address, printing ("A" & UBound(MyArray) + 1) IS
giving me
"A9" (there are 8 elements in my array), so that's working, and I can
print the
elements in the array. I set a range and filled it EXACTLY like this
before,
except for that I was using Range("A1:A" & UBound(MyArray) + 1), and that
worked
perfectly. This seems so slightly different I can't figure out whay I'd
get type
mismatch.

As long as I'm talking about it, does anyone know how to paste an array's
values
by just selecting the first cell you want? In Excel, if you have
ranges/values
in the clipboard, you can click just one cell and paste; is there a way
in vba
to just click one cell and transpose your array successfully, besides
looping
through every element and offsetting every time?

Thanks again. I know I'm posting a lot, but believe me, I'm spending
hours on
everything I can't quite get. And I found out how to do some great stuff
I never
knew about before, but unfortunately none of it applies to what I'm
doing.


--
Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 420
Default Referring to ranges as Cell, Range, and variables

Or share your updated code and also share what was in that array. Maybe your
array didn't get created the way you wanted.

On 10/17/2010 12:52, CompleteNewb wrote:
Dave, thanks for trying to help, but I'm getting invalid use of Resize error
when trying to do below; in case it was the way I was referring to my ranges as
variables, or cells, or some other incorrect way of doing things, I tried doing
exactly what's below, and still got invalid use of resize (even though the vba
editor was putting up the autocomplete help as I was putting "resize" in.


"Dave Peterson" wrote in message
...
I'd break it down into smaller pieces...

Option Explicit
Sub testme()

Dim myArray As Variant
Dim DestCell As Range

myArray = Array("a", "b", "c", "d")

With Worksheets("mySheet")
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With

DestCell.Resize(UBound(myArray) - LBound(myArray) + 1, 1).Value _
= Application.Transpose(myArray)

End Sub



On 10/15/2010 02:20, CompleteNewb wrote:
I have been experimenting with the whole Cells([whatever, whatever]),
Range(Whatever, whatever), using variables that are ranges, etc., and I swear
every time I think I have figured out how to refer to things, I get the error
about type mismatch. I mean really.

Can anyone tell me how to get this to work:

Worksheets("MySheet").Range("A65536").End(xlUp).Of fset(1, 0).Address , ("A" &
UBound(MyArray) + 1) = Application.WorksheetFunction.Transpose(MyArray)

This is supposed to find the first blank cell in A, set the range from there to
the number of elements in my array down, then put in my array values. I can
debug.print the 1st address, printing ("A" & UBound(MyArray) + 1) IS giving me
"A9" (there are 8 elements in my array), so that's working, and I can print the
elements in the array. I set a range and filled it EXACTLY like this before,
except for that I was using Range("A1:A" & UBound(MyArray) + 1), and that worked
perfectly. This seems so slightly different I can't figure out whay I'd get type
mismatch.

As long as I'm talking about it, does anyone know how to paste an array's values
by just selecting the first cell you want? In Excel, if you have ranges/values
in the clipboard, you can click just one cell and paste; is there a way in vba
to just click one cell and transpose your array successfully, besides looping
through every element and offsetting every time?

Thanks again. I know I'm posting a lot, but believe me, I'm spending hours on
everything I can't quite get. And I found out how to do some great stuff I never
knew about before, but unfortunately none of it applies to what I'm doing.


--
Dave Peterson



--
Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Referring to ranges as Cell, Range, and variables

I'm sorry, the problem was I forgot the () on the dimming of the array:

Dim MyArray() as variant.

This is probably not needed when you fill it specifically with known values,
as in your example, but I was using my own arrayname at first. My
apologies.

Thanks for the hlp on this, it's panning out to be useful in several of my
other problems I was having.

"Dave Peterson" wrote in message
...
Or share your updated code and also share what was in that array. Maybe
your array didn't get created the way you wanted.

On 10/17/2010 12:52, CompleteNewb wrote:
Dave, thanks for trying to help, but I'm getting invalid use of Resize
error
when trying to do below; in case it was the way I was referring to my
ranges as
variables, or cells, or some other incorrect way of doing things, I tried
doing
exactly what's below, and still got invalid use of resize (even though
the vba
editor was putting up the autocomplete help as I was putting "resize" in.


"Dave Peterson" wrote in message
...
I'd break it down into smaller pieces...

Option Explicit
Sub testme()

Dim myArray As Variant
Dim DestCell As Range

myArray = Array("a", "b", "c", "d")

With Worksheets("mySheet")
Set DestCell = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0)
End With

DestCell.Resize(UBound(myArray) - LBound(myArray) + 1, 1).Value _
= Application.Transpose(myArray)

End Sub



On 10/15/2010 02:20, CompleteNewb wrote:
I have been experimenting with the whole Cells([whatever, whatever]),
Range(Whatever, whatever), using variables that are ranges, etc., and I
swear
every time I think I have figured out how to refer to things, I get the
error
about type mismatch. I mean really.

Can anyone tell me how to get this to work:

Worksheets("MySheet").Range("A65536").End(xlUp).Of fset(1, 0).Address ,
("A" &
UBound(MyArray) + 1) = Application.WorksheetFunction.Transpose(MyArray)

This is supposed to find the first blank cell in A, set the range from
there to
the number of elements in my array down, then put in my array values. I
can
debug.print the 1st address, printing ("A" & UBound(MyArray) + 1) IS
giving me
"A9" (there are 8 elements in my array), so that's working, and I can
print the
elements in the array. I set a range and filled it EXACTLY like this
before,
except for that I was using Range("A1:A" & UBound(MyArray) + 1), and
that worked
perfectly. This seems so slightly different I can't figure out whay I'd
get type
mismatch.

As long as I'm talking about it, does anyone know how to paste an
array's values
by just selecting the first cell you want? In Excel, if you have
ranges/values
in the clipboard, you can click just one cell and paste; is there a way
in vba
to just click one cell and transpose your array successfully, besides
looping
through every element and offsetting every time?

Thanks again. I know I'm posting a lot, but believe me, I'm spending
hours on
everything I can't quite get. And I found out how to do some great
stuff I never
knew about before, but unfortunately none of it applies to what I'm
doing.


--
Dave Peterson



--
Dave Peterson


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Referring to Range addresses when in variables CompleteNewb[_2_] Excel Programming 2 October 17th 10 11:56 PM
Referring to specific cell in named range in Excel formula Nigel Barton Excel Worksheet Functions 3 August 18th 09 04:25 PM
Referring to a cell by entering an integer; RANGE functions Tim Murray Excel Worksheet Functions 5 May 24th 08 11:21 PM
Referring to first cell in a range FARAZ QURESHI Excel Discussion (Misc queries) 5 December 26th 07 05:14 PM
Cell Variables and Ranges jcottam Excel Discussion (Misc queries) 2 March 31st 06 07:33 PM


All times are GMT +1. The time now is 12:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"