Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel: limiting range of code

Status
Not open for further replies.

dh42891

Technical User
Oct 7, 2003
107
0
0
US
I need to limit the range the date code I got from an FAQ that places the current date in the neighboring cell. That code works fantastic, but it applies to the entire column. I only need it to apply itself to rows 3 through 45. Not sure what to manipulate to accomplish that. This is the code from the FAQ:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Cell As Range
    For Each Cell In Target
        With Cell
            If .Column = Range("G:G").Column Then
                Cells(.Row, "F").Value = Int(Now)
            End If
        End With
    Next Cell
End Sub

Thanks!

dylan
 
What exactly are you trying to do with this? I'm not sure a VBA solution is required here - could you be more specific?
 
I want to keep track of the date that a cell is changed. I don't want the date to be recalculated everytime I open or refresh Excel, and I don't need it for every cell in column G. The code I posted does exactly what I want, just for too broad of an area. Does that help clarify? Thanks,

dylan
 
dh,

To set rows 3 to 45 in column F to Int(Now) try;

ActiveSheet.Columns("F:F").Rows("3:45").Value = Int(Now())

or

ActiveSheet.Range("F3:F45").Value = Int(Now))

or

ActiveSheet.Range(Cells(3, 6),Cells(45, 6)).Value = Int(Now))

HTH Hugh
 
Instead of using Int(Now) use Date.

Cheers, Glenn.

Did you hear about the literalist show-jumper? He broke his nose jumping against the clock.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top