Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10
Default looping through an giving values to cells in vba

i am trying to write values from an array into a row of cells, ive written a
sub which i pass a parameter array to which should loop through a row of
cells and put the next value in the array into the cell, here is what i think
should work (but doesnt)

Public Sub GenerateHeadings(headerNo As Integer, lastRow As Integer,
ParamArray ParameterArray() As Variant)
'pass in the headings that you want to have in an array and then out them
into 'each cell formating as required
Dim counter As Integer
Dim result As Integer

For counter = 0 To UBound(ParameterArray, 1)
Worksheets("Campaigns by Channel").Cells(counter, 3).Value =
ParameterArray(counter)
Next counter

end sub

this doesnt work, infact the stumbling block is when i use a variable as the
cells index number. why is that not working when

Dim Counter As Integer
For Counter = 1 To 20
Worksheets("Sheet1").Cells(Counter, 3).Value = Counter
Next Counter

(from the help file) does? i know that my parameter array is workign fine,
its just that index variable. Has been frustrating me since yesterday, am
going to change tact and do some SQL!
any help will be gratfully received

Amit
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default looping through an giving values to cells in vba

counter starting at zero is O.K. for the array, but not for the range
reference.

You need something like:

Worksheets("Campaigns by Channel").Cells(counter+1, 3).Value =

because the lowest cells reference is Cells(1, 1)
--
Gary''s Student


"DowningDevelopments" wrote:

i am trying to write values from an array into a row of cells, ive written a
sub which i pass a parameter array to which should loop through a row of
cells and put the next value in the array into the cell, here is what i think
should work (but doesnt)

Public Sub GenerateHeadings(headerNo As Integer, lastRow As Integer,
ParamArray ParameterArray() As Variant)
'pass in the headings that you want to have in an array and then out them
into 'each cell formating as required
Dim counter As Integer
Dim result As Integer

For counter = 0 To UBound(ParameterArray, 1)
Worksheets("Campaigns by Channel").Cells(counter, 3).Value =
ParameterArray(counter)
Next counter

end sub

this doesnt work, infact the stumbling block is when i use a variable as the
cells index number. why is that not working when

Dim Counter As Integer
For Counter = 1 To 20
Worksheets("Sheet1").Cells(Counter, 3).Value = Counter
Next Counter

(from the help file) does? i know that my parameter array is workign fine,
its just that index variable. Has been frustrating me since yesterday, am
going to change tact and do some SQL!
any help will be gratfully received

Amit

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10
Default looping through an giving values to cells in vba

so simple but so frustrating!!!!

thanks gary's student!

"Gary''s Student" wrote:

counter starting at zero is O.K. for the array, but not for the range
reference.

You need something like:

Worksheets("Campaigns by Channel").Cells(counter+1, 3).Value =

because the lowest cells reference is Cells(1, 1)
--
Gary''s Student


"DowningDevelopments" wrote:

i am trying to write values from an array into a row of cells, ive written a
sub which i pass a parameter array to which should loop through a row of
cells and put the next value in the array into the cell, here is what i think
should work (but doesnt)

Public Sub GenerateHeadings(headerNo As Integer, lastRow As Integer,
ParamArray ParameterArray() As Variant)
'pass in the headings that you want to have in an array and then out them
into 'each cell formating as required
Dim counter As Integer
Dim result As Integer

For counter = 0 To UBound(ParameterArray, 1)
Worksheets("Campaigns by Channel").Cells(counter, 3).Value =
ParameterArray(counter)
Next counter

end sub

this doesnt work, infact the stumbling block is when i use a variable as the
cells index number. why is that not working when

Dim Counter As Integer
For Counter = 1 To 20
Worksheets("Sheet1").Cells(Counter, 3).Value = Counter
Next Counter

(from the help file) does? i know that my parameter array is workign fine,
its just that index variable. Has been frustrating me since yesterday, am
going to change tact and do some SQL!
any help will be gratfully received

Amit

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default looping through an giving values to cells in vba

Don't beat your self up over this one.

It's the developers of VBA that were inconsistent.

Why did they start arrays at zero and rows & columns at one??
--
Gary's Student


"DowningDevelopments" wrote:

so simple but so frustrating!!!!

thanks gary's student!

"Gary''s Student" wrote:

counter starting at zero is O.K. for the array, but not for the range
reference.

You need something like:

Worksheets("Campaigns by Channel").Cells(counter+1, 3).Value =

because the lowest cells reference is Cells(1, 1)
--
Gary''s Student


"DowningDevelopments" wrote:

i am trying to write values from an array into a row of cells, ive written a
sub which i pass a parameter array to which should loop through a row of
cells and put the next value in the array into the cell, here is what i think
should work (but doesnt)

Public Sub GenerateHeadings(headerNo As Integer, lastRow As Integer,
ParamArray ParameterArray() As Variant)
'pass in the headings that you want to have in an array and then out them
into 'each cell formating as required
Dim counter As Integer
Dim result As Integer

For counter = 0 To UBound(ParameterArray, 1)
Worksheets("Campaigns by Channel").Cells(counter, 3).Value =
ParameterArray(counter)
Next counter

end sub

this doesnt work, infact the stumbling block is when i use a variable as the
cells index number. why is that not working when

Dim Counter As Integer
For Counter = 1 To 20
Worksheets("Sheet1").Cells(Counter, 3).Value = Counter
Next Counter

(from the help file) does? i know that my parameter array is workign fine,
its just that index variable. Has been frustrating me since yesterday, am
going to change tact and do some SQL!
any help will be gratfully received

Amit

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
How do I sum up values only in cells that are color filled? TryingExcel Excel Worksheet Functions 7 April 12th 09 03:34 PM
Linking Groups of cells between workbooks vnacj-joe Excel Discussion (Misc queries) 4 June 14th 07 05:18 PM
Looping between sheets picking up values on the way bungie Excel Worksheet Functions 3 March 5th 06 07:22 AM
Is there way to enter multiple values into excel cells w/ a form? grassfed Excel Discussion (Misc queries) 1 June 22nd 05 05:26 PM
How To Use Cells Without Values in a Formula Roger H. Excel Worksheet Functions 2 April 6th 05 01:01 AM


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

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

About Us

"It's about Microsoft Excel"