Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default Simple Do Loop!

Hi

I have a list of dates in D that will be varying in size. In G I want to
add the formula =TODAY()-D2, etc.

I want this to appear as the result of a certain macro and deleted if
another macro is run, as something else will go here. This part I can manage.

I'm struggling with making the Do Loop only continue if there is something
in D.

Any help, much appreciated!

Adam
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Simple Do Loop!

Adam,

Try this

Lastrow = Cells(Cells.Rows.Count, "D").End(xlUp).Row
Range("G2:G" & Lastrow).Formula = "=TODAY()-D2"

Mike

"Adam" wrote:

Hi

I have a list of dates in D that will be varying in size. In G I want to
add the formula =TODAY()-D2, etc.

I want this to appear as the result of a certain macro and deleted if
another macro is run, as something else will go here. This part I can manage.

I'm struggling with making the Do Loop only continue if there is something
in D.

Any help, much appreciated!

Adam

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 287
Default Simple Do Loop!

Spot on

Thanks Mike

Adam


"Mike H" wrote:

Adam,

Try this

Lastrow = Cells(Cells.Rows.Count, "D").End(xlUp).Row
Range("G2:G" & Lastrow).Formula = "=TODAY()-D2"

Mike

"Adam" wrote:

Hi

I have a list of dates in D that will be varying in size. In G I want to
add the formula =TODAY()-D2, etc.

I want this to appear as the result of a certain macro and deleted if
another macro is run, as something else will go here. This part I can manage.

I'm struggling with making the Do Loop only continue if there is something
in D.

Any help, much appreciated!

Adam

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Simple Do Loop!

Try code like the following

Dim R As Range
Set R = Range("D1") ' or starting cell
Do Until R.Value = vbNullString
' do something with R
Set R = R(2, 1) ' move R down one row
Loop

This will start at D1 or whatever cell you specify in the Range
object, and move down one row at a time until an empty cell is
encountered. Replace the " ' do something with R " with your actual
code. Note that in this sort of loop, the ActiveCell is never changed,
so if the ActiveCell pointed to D1 before to loop executed, it will
still point to D1 even after the loop has set R down to D100. The
ActiveCell never changes unless you write code to explicitly change
it.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Mon, 28 Sep 2009 03:47:01 -0700, Adam
wrote:

Hi

I have a list of dates in D that will be varying in size. In G I want to
add the formula =TODAY()-D2, etc.

I want this to appear as the result of a certain macro and deleted if
another macro is run, as something else will go here. This part I can manage.

I'm struggling with making the Do Loop only continue if there is something
in D.

Any help, much appreciated!

Adam

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
Simple Loop John Excel Programming 4 July 17th 09 03:01 PM
Simple Loop Help Please pianoman[_24_] Excel Programming 0 May 24th 06 02:34 PM
Simple Loop Help Please HBF Excel Programming 0 May 24th 06 02:30 PM
Simple loop? bushtor Excel Programming 3 September 13th 05 01:45 PM
Some help w/ simple loop, please? terry b Excel Programming 6 February 6th 05 06:17 PM


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