Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 158
Default Naming of column index

Dear experts,

I've a marco in my worksheet which is used to show auto current date and
time when something is filled in column A. The code is:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Not Intersect(Target, Range("A3:A50")) Is Nothing Then
With Target(1, 4)
.Value = Date
.EntireColumn.AutoFit
End With
With Target(1, 5)
.Value = Time
.EntireColumn.AutoFit
End With
End If
End Sub

However, this time, if I change the target range from column A to C and I
want the auto date and time to be shown in column A & B, I then change the
column index in the code from 4 to -2 for the date and from 5 to -1 for the
time, but it did not work.
Could any experts teach me how to correct the code.

Thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,480
Default Naming of column index

Hi

Try
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Not Intersect(Target, Range("C3:C50")) Is Nothing Then
With Target.offset(0, -2)
.Value = Date
.EntireColumn.AutoFit
End With
With Target.offset(0,-1)
.Value = Time
.EntireColumn.AutoFit
End With
End If
End Sub


--
Regards
Roger Govier



"Freshman" wrote in message
...
Dear experts,

I've a marco in my worksheet which is used to show auto current date and
time when something is filled in column A. The code is:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Not Intersect(Target, Range("A3:A50")) Is Nothing Then
With Target(1, 4)
.Value = Date
.EntireColumn.AutoFit
End With
With Target(1, 5)
.Value = Time
.EntireColumn.AutoFit
End With
End If
End Sub

However, this time, if I change the target range from column A to C and I
want the auto date and time to be shown in column A & B, I then change the
column index in the code from 4 to -2 for the date and from 5 to -1 for
the
time, but it did not work.
Could any experts teach me how to correct the code.

Thanks in advance



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 158
Default Naming of column index

Hi Roger,

It works wonderful. Thanks a million. Best regards.

"Roger Govier" wrote:

Hi

Try
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Not Intersect(Target, Range("C3:C50")) Is Nothing Then
With Target.offset(0, -2)
.Value = Date
.EntireColumn.AutoFit
End With
With Target.offset(0,-1)
.Value = Time
.EntireColumn.AutoFit
End With
End If
End Sub


--
Regards
Roger Govier



"Freshman" wrote in message
...
Dear experts,

I've a marco in my worksheet which is used to show auto current date and
time when something is filled in column A. The code is:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
If Not Intersect(Target, Range("A3:A50")) Is Nothing Then
With Target(1, 4)
.Value = Date
.EntireColumn.AutoFit
End With
With Target(1, 5)
.Value = Time
.EntireColumn.AutoFit
End With
End If
End Sub

However, this time, if I change the target range from column A to C and I
want the auto date and time to be shown in column A & B, I then change the
column index in the code from 4 to -2 for the date and from 5 to -1 for
the
time, but it did not work.
Could any experts teach me how to correct the code.

Thanks in advance




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
Naming cells in a table based on column and row label [email protected] Excel Discussion (Misc queries) 3 December 3rd 06 11:16 AM
naming a grouped column Amie Excel Worksheet Functions 0 July 25th 06 10:43 PM
Naming Row/column in same cell? Bob Setting up and Configuration of Excel 1 July 13th 06 03:58 PM
Excell column naming PROBLEM, HELP PLEASE ANA Excel Discussion (Misc queries) 2 September 8th 05 03:50 AM
Naming column in Index Function mlkpied Excel Worksheet Functions 3 December 7th 04 12:20 AM


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