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

Is it possible to have a row with a date in one cell and a dollar amoun
in another, have the dollar amount move one cell to the right once
certain time has passed?

Example:
Once 30 days has elapsed, have $10.00 move from column L to

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Dated Fields

Is this possibl

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Dated Fields

Yes.

Option Explicit
Sub testme()
With Worksheets("sheet1")
If .Range("a1").Value < Date - 30 Then
If .Range("M1").Value = "" Then
.Range("M1").Value = .Range("L1").Value
.Range("l1").ClearContents
End If
End If
End With
End Sub


You could even go through a range of cells:

Option Explicit
Sub testme()

Dim myCell As Range
Dim myRng As Range


With Worksheets("sheet1")
Set myRng = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))

For Each myCell In myRng.Cells
With myCell
If IsDate(.Value) Then
If .Value < Date - 30 Then
If .Cells(.Row, "M").Value = "" Then
.Cells(.Row, "M").Value = .Cells(.Row, "L").Value
.Cells(.Row, "L").ClearContents
End If
End If
End If
End With
Next myCell
End With
End Sub

(I added one more check--isdate().)



"stck2mlon <" wrote:

Is it possible to have a row with a date in one cell and a dollar amount
in another, have the dollar amount move one cell to the right once a
certain time has passed?

Example:
Once 30 days has elapsed, have $10.00 move from column L to M

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Dated Fields

This is great...What is a good way to test this and where should it g
in my VBA or someplace else entirely

--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Dated Fields

Can this be in a field or in my userform

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Dated Fields

Dave,

Would this look for the date in column G, row 3 and move amount i
column L to coulmn N? It isn't giving an error, nor is it working. An
suggestions?

Sub UserForm_initialize()
Dim myCell As Range
Dim myRng As Range
With Worksheets("Active Collection")
Set myRng = .Range("g3", .Cells(.Rows.Count, "G").End(xlUp))
For Each myCell In myRng.Cells
With myCell
If IsDate(.Value) Then
If .Value < Date - 30 Then
If .Cells(.Row, "M").Value = "" Then
.Cells(.Row, "M").Value = .Cells(.Row
"L").Value
.Cells(.Row, "L").ClearContents
End If
End If
End If
End With
Next myCell
End With
End Su

--
Message posted from http://www.ExcelForum.com

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Dated Fields

Sorry, I missed your followups.

But I'd put the code into a general module and run it via:
tools|macro|macros...
(or plop a button from the forms toolbar onto the worksheet and assign this
macro to the button.)

but I think you got hit by the "With/End with" structure (and I'm not sure if
leading dots were included in your code. Sometimes posting to the newsgroups
via those web based interfaces seems to cause problems with formatting and first
characters in the line.)

Anyway:
this portion looks like trouble under some circumstances (and to make matters
worse, you copied from my post! I didn't notice that until now. Darn!)

With myCell
If IsDate(.Value) Then
If .Value < Date - 30 Then
If .Cells(.Row, "M").Value = "" Then
Cells(.Row, "M").Value = .Cells(.Row,"L").Value
Cells(.Row, "L").ClearContents
End If
End If
End If
End With


This portion ".cells(.row,"M").value" refers to the previous With/End with. The
previous With in this case is with myCell.

Try this short test.

sub OhOh()
Dim mycell as range
set mycell = activesheet.range("c3")
with mycell
msgbox .cells(.row,"M").address
end with
end sub

I get $o$5 in the message box--not what I intended.

That example was equivalent to:
msgbox activesheet.range("c3").cells(3,"M").address
down 2 rows (.cells(x,y) is one's based).
and over 12 columns.

I could have removed that leading dot--but that may not be safe either:

With myCell
If IsDate(.Value) Then
If .Value < Date - 30 Then
If Cells(.Row, "M").Value = "" Then
Cells(.Row, "M").Value = Cells(.Row,"L").Value
Cells(.Row, "L").ClearContents
End If
End If
End If
End With

Without a dot (.cells), this is called an unqualified range. If the code is in
a general module, it'll refer to the active worksheet--and that might not always
be "Active Collection".

So it's better to qualify those cells with something like:

Option Explicit
Sub testme01()
Dim myCell As Range
Dim myRng As Range
With Worksheets("Active Collection")
Set myRng = .Range("g3", .Cells(.Rows.Count, "G").End(xlUp))
For Each myCell In myRng.Cells
If IsDate(myCell.Value) Then
If myCell.Value < Date - 30 Then
If .Cells(myCell.Row, "M").Value = "" Then
.Cells(myCell.Row, "M").Value _
= .Cells(myCell.Row, "L").Value
.Cells(myCell.Row, "L").ClearContents
End If
End If
End If
Next myCell
End With
End Sub

The .cells() stuff refers back to the previous with/end with. And now it refers
to that "active collection" worksheet.

Again, sorry about the bad code.


"stck2mlon <" wrote:

Dave,

Would this look for the date in column G, row 3 and move amount in
column L to coulmn N? It isn't giving an error, nor is it working. Any
suggestions?

Sub UserForm_initialize()
Dim myCell As Range
Dim myRng As Range
With Worksheets("Active Collection")
Set myRng = .Range("g3", .Cells(.Rows.Count, "G").End(xlUp))
For Each myCell In myRng.Cells
With myCell
If IsDate(.Value) Then
If .Value < Date - 30 Then
If .Cells(.Row, "M").Value = "" Then
Cells(.Row, "M").Value = .Cells(.Row,
"L").Value
Cells(.Row, "L").ClearContents
End If
End If
End If
End With
Next myCell
End With
End Sub

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson

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
colour change of dated box barkat New Users to Excel 2 February 22nd 09 11:24 PM
How do I set up 12 months/31 days each dated spreadsheets? kayak99 New Users to Excel 6 February 5th 09 11:15 PM
A macro that will hide all but the last 20 dated rows. Mac0001UK Excel Discussion (Misc queries) 1 September 19th 08 08:45 AM
Charting Dated Data Marsh Charts and Charting in Excel 1 January 7th 08 06:46 PM
print spreadsheet with each coming day dated on it for 2006. Megan Excel Discussion (Misc queries) 20 March 13th 06 09:02 PM


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