Hello,
The help I've found on this subject has been great, but now I think my problem is more specific. I have the following code applied to one worksheet (right click sheet tab and click "view code") and it works very well:
Now I tried to apply this code to ALL worksheets by putting it in ThisWorkbook in the VB editor (right click "ThisWorkbook" in the VB editor and click "view code"). All I changed was the first line of the code. Here is that code:
The problem is the If statement only works on the first worksheet. This statement inputs the date and time into columns "A" and "B" when column "C" is changed. The dates and times are not appearing in their columns for all sheets (except Sheet1). The problem must lie with either the If statement or the two With statements. Anyone have a solution?
Thanks very much.
-Nick
The help I've found on this subject has been great, but now I think my problem is more specific. I have the following code applied to one worksheet (right click sheet tab and click "view code") and it works very well:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("C10:C100000")) Is Nothing Then
With Target(1, -1)
.Value = Date
.EntireColumn.AutoFit
End With
With Target(1, 0)
.Value = Time
.EntireColumn.AutoFit
End With
End If
Columns("B").Hidden = True
Dim MyRange As Range, c As Range
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set MyRange = Range("A2:A4436")
MyRange.EntireRow.Hidden = False
For Each c In MyRange
If IsDate(c.Value) And c.Value < Date Then
c.EntireRow.Hidden = True
End If
Next
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Now I tried to apply this code to ALL worksheets by putting it in ThisWorkbook in the VB editor (right click "ThisWorkbook" in the VB editor and click "view code"). All I changed was the first line of the code. Here is that code:
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("C10:C100000")) Is Nothing Then
With Target(1, -1)
.Value = Date
.EntireColumn.AutoFit
End With
With Target(1, 0)
.Value = Time
.EntireColumn.AutoFit
End With
End If
Columns("B").Hidden = True
Dim MyRange As Range, c As Range
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Set MyRange = Range("A2:A4436")
MyRange.EntireRow.Hidden = False
For Each c In MyRange
If IsDate(c.Value) And c.Value < Date Then
c.EntireRow.Hidden = True
End If
Next
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
The problem is the If statement only works on the first worksheet. This statement inputs the date and time into columns "A" and "B" when column "C" is changed. The dates and times are not appearing in their columns for all sheets (except Sheet1). The problem must lie with either the If statement or the two With statements. Anyone have a solution?
Thanks very much.
-Nick
Last edited: