Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default Using a variable in a range

Hi all,

I have the following code which determines the amount of rows:
Dim lastrow As Long
lastrow = range("A6").End(xlDown).Row

I now need to use the "lastrow" in the formula from Bob

For Each cell In ActiveSheet.range("BD6:BD10000")
If Not cell.HasFormula Then
cell.Value = Trim(cell.Value)
End If
In other words all the spreadsheets start at BD6 but the lenght is
variable. I have tried to piece it together but cannot get it to work.

thanks

Tempy

*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Using a variable in a range

Range(Cells(6, 56), Cells(lastrow, 56))

--

Vasant

"Tempy" wrote in message
...
Hi all,

I have the following code which determines the amount of rows:
Dim lastrow As Long
lastrow = range("A6").End(xlDown).Row

I now need to use the "lastrow" in the formula from Bob

For Each cell In ActiveSheet.range("BD6:BD10000")
If Not cell.HasFormula Then
cell.Value = Trim(cell.Value)
End If
In other words all the spreadsheets start at BD6 but the lenght is
variable. I have tried to piece it together but cannot get it to work.

thanks

Tempy

*** Sent via Developersdex http://www.developersdex.com ***



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default Using a variable in a range

Thanks for the reply Vasant, not being a programmer i do not know how
that goes together, could you help ?

Tempy

*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Using a variable in a range

I would use

Range("BD6:BD" & lastrow)

I think it is more explanatory :-)

I also suggest you work bottom up to get lastrow, unless you deliberately
want to avoid any rows after the first blank

lastrow = Cells(Rows.Count,"A").End(xlUp).Row

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Range(Cells(6, 56), Cells(lastrow, 56))

--

Vasant

"Tempy" wrote in message
...
Hi all,

I have the following code which determines the amount of rows:
Dim lastrow As Long
lastrow = range("A6").End(xlDown).Row

I now need to use the "lastrow" in the formula from Bob

For Each cell In ActiveSheet.range("BD6:BD10000")
If Not cell.HasFormula Then
cell.Value = Trim(cell.Value)
End If
In other words all the spreadsheets start at BD6 but the lenght is
variable. I have tried to piece it together but cannot get it to work.

thanks

Tempy

*** Sent via Developersdex http://www.developersdex.com ***





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default Using a variable in a range

Thank you Bob, more clear for newbies like me.

Tempy

*** Sent via Developersdex http://www.developersdex.com ***


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Using a variable in a range

"Bob Phillips" wrote in message
...
I think it is more explanatory :-)


Ah, but then one loses one's mystique <g.

Regards,

Vasant


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 to get a variable range Metin Excel Programming 3 January 27th 05 01:17 PM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
Using Variable in RANGE Jim[_31_] Excel Programming 1 April 26th 04 01:26 PM
Using Variable in RANGE Jim[_31_] Excel Programming 2 April 26th 04 01:18 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 11:59 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"