LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Setting a variable to range of cell values

Hi Robert

The code below should do what you want all I did was set another range
from the cell containing "Need header" to the offset column (0,11)
then I used an integer to iterate through the elements of the array
placing them in the cells.

Just a note of interest it is good practice to always declare your
variables as it leads to easier to read code and will help out with
any nasty spelling mistakes in you code that can take an age to find
manually.

Option Explicit
Dim MyArray As Variant
Dim range1 As Range
Dim A As Range
Dim MyCell, MyRng As Range
Dim i As Integer
Private Sub CommandButton1_Click()

MyArray = Sheets(2).[A1:L1]

With Sheets("Sheet3")

Set range1 = .Range("A1:A20")

For Each A In range1

i = 1

If A.Value = "Need header" Then

Set MyRng = Range(A, A.Offset(0, 11))'Set new range

For Each MyCell In MyRng

MyCell.Value = MyArray(1, i) 'Place array value in cell

i = i + 1 'Iterate Integer

Next MyCell 'Iterate Cell

End If

Next A

End With


End Sub


Hope this helps

S

 
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
Setting Range Variable Steve C Excel Programming 5 November 21st 06 08:03 AM
Setting a Variable range in VBA The Hawk Excel Programming 2 May 5th 06 03:11 AM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
Setting range value to a variable Todd Excel Programming 4 June 2nd 04 04:51 PM
Setting up a variable print range Gary[_5_] Excel Programming 5 July 31st 03 04:32 AM


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