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

Hi. I have a variable defined as below:
var3 = Cells(ActiveCell.Row, "D").Value

How can I convert var3 to be (in laymans terms) ActiveCell.Row, "D" through
BB xlleft

So if active row is 3, var 3 might be D3:G3, if G was the last data point
and H and to the right was blank.

Thanks!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Range as variable

Steph,

Dim Var3 As Range
Dim i As Integer

Set Var3 = Range(Cells(ActiveCell.Row, "D"), _
Cells(ActiveCell.Row, "D").End(xlToRight))

For i = 1 To Var3.Cells.Count
MsgBox Var3(i).Value
Next i

HTH,
Bernie
MS Excel MVP


"Steph" wrote in message
...
Hi. I have a variable defined as below:
var3 = Cells(ActiveCell.Row, "D").Value

How can I convert var3 to be (in laymans terms) ActiveCell.Row, "D"

through
BB xlleft

So if active row is 3, var 3 might be D3:G3, if G was the last data point
and H and to the right was blank.

Thanks!




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default Range as variable

Steph,

Sub test()

Dim last_column As Long
Dim row_data As Range
Dim data_cell As Range
Dim var3

With ActiveSheet
last_column = .Range("BB" & ActiveCell.Row).End(xlToLeft).Column
Set row_data = .Range(.Cells(ActiveCell.Row, 4), .Cells(ActiveCell.Row,
last_column))
row_data.Select
For Each data_cell In row_data
var3 = data_cell.Value
Debug.Print var3 'for testing
Next data_cell
End With

End Sub

hth,

Doug Glancy
"Steph" wrote in message
...
Hi. I have a variable defined as below:
var3 = Cells(ActiveCell.Row, "D").Value

How can I convert var3 to be (in laymans terms) ActiveCell.Row, "D"

through
BB xlleft

So if active row is 3, var 3 might be D3:G3, if G was the last data point
and H and to the right was blank.

Thanks!




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Range as variable

Steph wrote:
Hi. I have a variable defined as below:
var3 = Cells(ActiveCell.Row, "D").Value

How can I convert var3 to be (in laymans terms) ActiveCell.Row, "D" through
BB xlleft

So if active row is 3, var 3 might be D3:G3, if G was the last data point
and H and to the right was blank.

Thanks!


addr = Cells(ActiveCell.row, "IV").End(xlToLeft).Column
Set var3 = Range(Cells(ActiveCell.row, "D"), Cells(ActiveCell.row,
addr))
MsgBox var3.Address

Alan Beban
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
Variable range in VB famdamly Excel Discussion (Misc queries) 2 January 22nd 06 02:29 PM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
variable range: l just can't get there! ste mac Excel Programming 2 October 27th 03 06:43 PM
Variable Range Martin[_9_] Excel Programming 1 October 12th 03 05:09 PM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


All times are GMT +1. The time now is 02:36 AM.

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"