Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Range to an Array doesn't contain values

I am creating an array from a selection on a sheet. My test lines show the
array has the correct rows and columns by looking at X and Y. I put a
breakpoint in the for/next loop to look at each data value but they always
show empty.
Here is the code I'm using:
'Make this workbook active
ThisWorkbook.Activate
ActiveWorkbook.Sheets(2).Activate
'Make cell A1 active
Worksheets(2).Range("A1").Activate
'Select all active cells on sheet
ActiveCell.CurrentRegion.Select
'Send all active cells to vaData array
vaData = Range(ActiveWindow.RangeSelection.Address).Value

'Test lines
Dim x As Long
Dim y As Long
x = UBound(vaData, 1)
y = UBound(vaData, 2)
For rwData = LBound(vaData, 1) To UBound(vaData, 1)
Data = vaData(rwData, 1)
Next


thanks,
Jerry

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Range to an Array doesn't contain values

It seems to be working. What is it supposed to do? Select the used range on
Sheet2? That's what it's doing for me. I get all appropriate values for
vaData, UBound, and UBound. Maybe something got screwed up in Excel's
memory. Maybe you have to restart your computer.


HTH,
Ryan---
--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"JerryH" wrote:

I am creating an array from a selection on a sheet. My test lines show the
array has the correct rows and columns by looking at X and Y. I put a
breakpoint in the for/next loop to look at each data value but they always
show empty.
Here is the code I'm using:
'Make this workbook active
ThisWorkbook.Activate
ActiveWorkbook.Sheets(2).Activate
'Make cell A1 active
Worksheets(2).Range("A1").Activate
'Select all active cells on sheet
ActiveCell.CurrentRegion.Select
'Send all active cells to vaData array
vaData = Range(ActiveWindow.RangeSelection.Address).Value

'Test lines
Dim x As Long
Dim y As Long
x = UBound(vaData, 1)
y = UBound(vaData, 2)
For rwData = LBound(vaData, 1) To UBound(vaData, 1)
Data = vaData(rwData, 1)
Next


thanks,
Jerry

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Range to an Array doesn't contain values



"ryguy7272" wrote:

It seems to be working. What is it supposed to do? Select the used range on
Sheet2? That's what it's doing for me. I get all appropriate values for
vaData, UBound, and UBound. Maybe something got screwed up in Excel's
memory. Maybe you have to restart your computer.


HTH,
Ryan---


Yeah, on sheet two I have data in the first two columns that I want to send
to an array. In the same program I am opening another workbook and trying to
send a column of data into another array. Using the two arrays I will
generate a third array and insert it into a new column in the other workbook.
I have the same problem creating the array from the other workbook. I know
this works as it is something I have done in the past but for some reason any
array I create in this workbook ends up with empty values.
Thanks for trying it, I'm not sure now why it doesn't work for me.
Any more suggestions?

thanks,
Jerry

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Range to an Array doesn't contain values



"ryguy7272" wrote:

It seems to be working. What is it supposed to do? Select the used range on
Sheet2? That's what it's doing for me. I get all appropriate values for
vaData, UBound, and UBound. Maybe something got screwed up in Excel's
memory. Maybe you have to restart your computer.


HTH,
Ryan---


Ryan,
I tried copying this code into a new wookbook and it still doesn't work.
Just wondering how you had declared your variables. Here's how I declared
mine:

Dim vaData As Variant
Dim rwData As Long
Dim Data As String

I also tried to dim Data as Variant with same results.
Please let me know if you did something different.

thanks,
Jerry


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Range to an Array doesn't contain values

Maybe the file is corrupt. I'd say down it and reboot. I tried this code,
which is 99% your code, and it worked just fine for me:
Sub CopyToNew()
'Make this workbook active
ThisWorkbook.Activate
ActiveWorkbook.Sheets(2).Activate
'Make cell A1 active
Worksheets(2).Range("A1").Activate
'Select all active cells on sheet
ActiveCell.CurrentRegion.Select
'Send all active cells to vaData array
vaData = Range(ActiveWindow.RangeSelection.Address).Value

'Test lines
Dim x As Long
Dim y As Long
x = UBound(vaData, 1)
y = UBound(vaData, 2)
For rwData = LBound(vaData, 1) To UBound(vaData, 1)
Data = vaData(rwData, 1)
Next
Selection.Copy
ActiveWorkbook.Sheets(3).Activate
Worksheets(3).Range("D1").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End Sub

That copies the range to a new sheet not a new workbook, but almost the same
thing; just make a reference to the new Workbook. Here is an example:
http://www.eggheadcafe.com/software/...heet-to-n.aspx

Maybe you can pilfer some of that code.

Good luck,
Ryan---
--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"JerryH" wrote:



"ryguy7272" wrote:

It seems to be working. What is it supposed to do? Select the used range on
Sheet2? That's what it's doing for me. I get all appropriate values for
vaData, UBound, and UBound. Maybe something got screwed up in Excel's
memory. Maybe you have to restart your computer.


HTH,
Ryan---


Ryan,
I tried copying this code into a new wookbook and it still doesn't work.
Just wondering how you had declared your variables. Here's how I declared
mine:

Dim vaData As Variant
Dim rwData As Long
Dim Data As String

I also tried to dim Data as Variant with same results.
Please let me know if you did something different.

thanks,
Jerry




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Range to an Array doesn't contain values

I'm still trying to get this to work. I added a couple more test lines that
set a value into two array positions and they do show up when I look at
vaData in my for/next loops. The only thing I can think of is the variable
declarations.
Anyways, here is my test code that I added:

vaData(1, 1) = "Hello"
vaData(1, 2) = "There"

For rwData = LBound(vaData, 1) To UBound(vaData, 1)
For coData = LBound(vaData, 2) To UBound(vaData, 2)
Data = vaData(rwData, coData)
Next
Next

Through the loop vaData(1,1) and (1,2) contains the strings but after that
everything is empty again.

I've tried rebooting and starting a new workbook with this code but nothing
seems to get it to work.

Jerry

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Range to an Array doesn't contain values

Got it.

Had to change:
vaData = Range(ActiveWindow.RangeSelection.Address).Value

to:
vaData = Worksheets(2).Range(ActiveWindow.RangeSelection.Ad dress).Value

I was pulling data off the first sheet instead of the second. The first
sheet has no values for the first 3 columns so it filled my array with empty
values. It's odd because the line right before it works and selects the
correct cells on the second sheet but then feeds the array from the first
sheet without specifying which sheet to go to and copy into the array.

Hope this helps someone else in the future.

Jerry
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
paste values from an array to a range Nick_F Excel Programming 4 July 27th 07 05:11 AM
adding range values to array Gary Keramidas Excel Programming 2 March 12th 07 03:59 AM
Store range of values in an array Trevor Shuttleworth Excel Programming 6 November 8th 06 06:37 AM
range values in an array? Mike Excel Programming 3 December 16th 05 04:56 PM
Array of Values from Worksheet Range - What does it 'look' like? Alan Excel Programming 7 July 8th 04 01:06 PM


All times are GMT +1. The time now is 02:59 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"