Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Keeping the date fixed

Again, thanks a lot!! Your a lifesaver! Works perfect.

Wish you the best!

Shivam


On Feb 12, 1:40*pm, "Rick Rothstein"
wrote:
This is a more generalized version of the code I posted...

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
* Const ColumnsToCheck As String = "A:A,K:K"
* If Not Intersect(Target, Range(ColumnsToCheck)) Is Nothing Then
* * If Target.Value = "" Then
* * * Target.Offset(0, 1).Value = ""
* * Else
* * * Target.Offset(0, 1).Value = Now()
* * End If
* End If
End Sub

Just change the "A:A,K:K" in my assignment to the ColumnsToCheck constant to
include all the columns you want or need. So, for just Column A, you would
use...

Const ColumnsToCheck As String = "A:A"

For Columns A and K (as per your posting), you would use what I used in the
code above. If you wanted to add Column X to the mix, you would use this
assignment...

Const ColumnsToCheck As String = "A:A,K:K,X:X")

and so on.

--
Rick (MVP - Excel)

"Shivam.Shah" wrote in message

...
Hi Rick,

Thanks very much!! Also, if I want to apply it to more than one pair
of columns, do I have to just copy and paste the code multiple times
and change the target column? Right now I am using it in just column A
and B, but I also enter values in column K and want dates in column L.
So, do I just copy and paste code again and change the target?

Thanks again,

Shivam

On Feb 12, 1:09 pm, "Rick Rothstein"

wrote:
This should do what you want...


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Column = 1 Then
If Target.Value = "" Then
Target.Offset(0, 1).Value = ""
Else
Target.Offset(0, 1).Value = Now()
End If
End If
End Sub


--
Rick (MVP - Excel)


"Shivam.Shah" wrote in message


...


Hello,


I was wondering if I could get help to write a query for the scenario
whe


I enter a value in column A and a date appears in column B, which
stays fixed and does not change based on the current date. Also, if I
delete the value from Column A, then the date also gets deleted.


This is what I have so far:


Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Column = 1 Then
Target.Offset(0, 1).Value = Now()
End If
End Sub


The problem is, as I said, if I delete the value from column A, the
date still stays in column B, which I don't want it to.


Any help will be great.


Thanks very much!


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
Keeping date from changing Richard Excel Discussion (Misc queries) 5 April 30th 08 02:57 AM
Difference between fixed and variable date RC Excel Programming 3 December 8th 06 01:55 PM
Fixed time and date jk Excel Discussion (Misc queries) 8 September 28th 06 08:01 AM
Keeping the format of a date Louise Excel Worksheet Functions 5 September 15th 06 12:05 PM
Keeping a date when today's date changes dps9460 New Users to Excel 2 June 3rd 06 04:25 AM


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