Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default Set Range Question

I need to display an arrray of results that are passed to a routine. I can
get the desired output with the three options I've posted (really two
different approaches), but I'd like to understand why I have to substract 1
from the OutputCol to get the output into the desired column. In other words,
if I don't substract 1 from OutputCol the output is displayed in column 30
instead of column 29.

I could also use some help with the resize methodology in Option 3; I'm
really poking around on this one.

Here are the options I've used:
Dim OutputRow As Long, OutputCol As Long
Dim DestRange As Range
Dim ThisSheet As String

ThisSheet = ActiveSheet.Name
OutputRow = 5
OutputCol = 29

'Option 1
Set DestRange = Range(Worksheets(ThisSheet).Cells(OutputRow, OutputCol - 1), _
Worksheets(ThisSheet).Cells(OutputRow + UBound(DailyAvgData,
1), _
OutputCol + UBound(DailyAvgData, 2) - 1))

OR

'Option 2 (essentially the same as Option 1)
With Worksheets(ThisSheet)
Set DestRange = .Range(.Cells(OutputRow, OutputCol - 1), _
.Cells(OutputRow + UBound(DailyAvgData, 1), _
OutputCol + UBound(DailyAvgData, 2) - 1))
End With

OR

' Option 3 (a variation of a post from Leo Hauser)
With Worksheets(ThisSheet)
Set DestRange = .Range(.Cells(OutputRow, OutputCol - 1), _
.Cells(OutputRow, OutputCol - 1)). _
Resize(UBound(DailyAvgData, 1), UBound(DailyAvgData, 2) + 1)
End With

' Output the array
DestRange.Value = DailyAvgData

Thanks in advance,
Raul

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Set Range Question

Excel defaults to 0 (zero) for the first item in an array, so column A in an
array is 0 and column AD is 29. So to get the result to be column AC which
Excel sees as 28, you must subtract 1. Confused?

This from VBA Help:
You can use the Option Base statement at the top of a module to change the
default index of the first element from 0 to 1. In the following example, the
Option Base statement changes the index for the first element, and the Dim
statement declares the array variable curExpense with 365 elements.

Option Base 1
Dim curExpense(365) As Currency



"Raul" wrote:

I need to display an arrray of results that are passed to a routine. I can
get the desired output with the three options I've posted (really two
different approaches), but I'd like to understand why I have to substract 1
from the OutputCol to get the output into the desired column. In other words,
if I don't substract 1 from OutputCol the output is displayed in column 30
instead of column 29.

I could also use some help with the resize methodology in Option 3; I'm
really poking around on this one.

Here are the options I've used:
Dim OutputRow As Long, OutputCol As Long
Dim DestRange As Range
Dim ThisSheet As String

ThisSheet = ActiveSheet.Name
OutputRow = 5
OutputCol = 29

'Option 1
Set DestRange = Range(Worksheets(ThisSheet).Cells(OutputRow, OutputCol - 1), _
Worksheets(ThisSheet).Cells(OutputRow + UBound(DailyAvgData,
1), _
OutputCol + UBound(DailyAvgData, 2) - 1))

OR

'Option 2 (essentially the same as Option 1)
With Worksheets(ThisSheet)
Set DestRange = .Range(.Cells(OutputRow, OutputCol - 1), _
.Cells(OutputRow + UBound(DailyAvgData, 1), _
OutputCol + UBound(DailyAvgData, 2) - 1))
End With

OR

' Option 3 (a variation of a post from Leo Hauser)
With Worksheets(ThisSheet)
Set DestRange = .Range(.Cells(OutputRow, OutputCol - 1), _
.Cells(OutputRow, OutputCol - 1)). _
Resize(UBound(DailyAvgData, 1), UBound(DailyAvgData, 2) + 1)
End With

' Output the array
DestRange.Value = DailyAvgData

Thanks in advance,
Raul

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default Set Range Question

Thanks JLGWhiz!

Any thoughts about the syntax on the resize statement?

Thanks again,
Raul

"JLGWhiz" wrote:

Excel defaults to 0 (zero) for the first item in an array, so column A in an
array is 0 and column AD is 29. So to get the result to be column AC which
Excel sees as 28, you must subtract 1. Confused?

This from VBA Help:
You can use the Option Base statement at the top of a module to change the
default index of the first element from 0 to 1. In the following example, the
Option Base statement changes the index for the first element, and the Dim
statement declares the array variable curExpense with 365 elements.

Option Base 1
Dim curExpense(365) As Currency



"Raul" wrote:

I need to display an arrray of results that are passed to a routine. I can
get the desired output with the three options I've posted (really two
different approaches), but I'd like to understand why I have to substract 1
from the OutputCol to get the output into the desired column. In other words,
if I don't substract 1 from OutputCol the output is displayed in column 30
instead of column 29.

I could also use some help with the resize methodology in Option 3; I'm
really poking around on this one.

Here are the options I've used:
Dim OutputRow As Long, OutputCol As Long
Dim DestRange As Range
Dim ThisSheet As String

ThisSheet = ActiveSheet.Name
OutputRow = 5
OutputCol = 29

'Option 1
Set DestRange = Range(Worksheets(ThisSheet).Cells(OutputRow, OutputCol - 1), _
Worksheets(ThisSheet).Cells(OutputRow + UBound(DailyAvgData,
1), _
OutputCol + UBound(DailyAvgData, 2) - 1))

OR

'Option 2 (essentially the same as Option 1)
With Worksheets(ThisSheet)
Set DestRange = .Range(.Cells(OutputRow, OutputCol - 1), _
.Cells(OutputRow + UBound(DailyAvgData, 1), _
OutputCol + UBound(DailyAvgData, 2) - 1))
End With

OR

' Option 3 (a variation of a post from Leo Hauser)
With Worksheets(ThisSheet)
Set DestRange = .Range(.Cells(OutputRow, OutputCol - 1), _
.Cells(OutputRow, OutputCol - 1)). _
Resize(UBound(DailyAvgData, 1), UBound(DailyAvgData, 2) + 1)
End With

' Output the array
DestRange.Value = DailyAvgData

Thanks in advance,
Raul

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
Range question Jock Excel Worksheet Functions 3 March 19th 08 04:36 PM
Range Question Peter[_8_] Excel Discussion (Misc queries) 3 December 11th 07 02:37 AM
Range Question / error 1004: method Range of object Worksheet has failed Paul Excel Programming 3 April 7th 05 02:56 PM
Range question strataguru[_19_] Excel Programming 2 September 25th 04 12:57 AM
Range.Formula and Range question using Excel Automation [email protected] Excel Programming 0 September 19th 03 04:53 AM


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

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"