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

When i manually delete times (to simulate what would happen if an incorrect
number is typed in and had to be manually corrected) and the column number is
9 the following code gives me an error on the line marked. Can anybody tell
me why. Thanks.



Private Sub Worksheet_Change(ByVal Target As Range)

Application.ScreenUpdating = False


'Column K is column 11
If Target.Column = 11 And Target.Row = 5 Then

TRow = Target.Row
Val1 = Range("G" & TRow).End(xlToRight).Offset(0, -1)
Val2 = Hour(Range("G" & TRow).End(xlToRight).Offset(0, -1))
Val3 = Minute(Range("G" & TRow).End(xlToRight).Offset(0, -1))
Val4 = Second(Range("G" & TRow).End(xlToRight).Offset(0, -1))
val5 = Sheets("timing sheet").Range("c21").Value / 24

If Range("G" & TRow).End(xlToRight).Offset(0, -1).Column < 10 Then

Sheets("a grade").Range("i" & TRow) = 0 'error here

ElseIf Val1 < val5 Then
Sheets("a grade").Range("i" & TRow) = 1000 + Sheets("a grade").Range("j" &
TRow) + (24 - Val2) / 100 + _
(60 - Val3) / 10000 + (60 - Val4) / 1000000
Else
Sheets("a grade").Range("i" & TRow) = 4000 + Sheets("a grade").Range("j" &
TRow) + (24 - Val2) / 100 + _
(60 - Val3) / 10000 + (60 - Val4) / 1000000

End If
End If


Application.ScreenUpdating = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 204
Default error in code

not sure if it is important but when you delete times you delete 2 cells
together. columns 11 and 12. Thought I'd better mention this in case it is
effecting something.

"NDBC" wrote:

When i manually delete times (to simulate what would happen if an incorrect
number is typed in and had to be manually corrected) and the column number is
9 the following code gives me an error on the line marked. Can anybody tell
me why. Thanks.



Private Sub Worksheet_Change(ByVal Target As Range)

Application.ScreenUpdating = False


'Column K is column 11
If Target.Column = 11 And Target.Row = 5 Then

TRow = Target.Row
Val1 = Range("G" & TRow).End(xlToRight).Offset(0, -1)
Val2 = Hour(Range("G" & TRow).End(xlToRight).Offset(0, -1))
Val3 = Minute(Range("G" & TRow).End(xlToRight).Offset(0, -1))
Val4 = Second(Range("G" & TRow).End(xlToRight).Offset(0, -1))
val5 = Sheets("timing sheet").Range("c21").Value / 24

If Range("G" & TRow).End(xlToRight).Offset(0, -1).Column < 10 Then

Sheets("a grade").Range("i" & TRow) = 0 'error here

ElseIf Val1 < val5 Then
Sheets("a grade").Range("i" & TRow) = 1000 + Sheets("a grade").Range("j" &
TRow) + (24 - Val2) / 100 + _
(60 - Val3) / 10000 + (60 - Val4) / 1000000
Else
Sheets("a grade").Range("i" & TRow) = 4000 + Sheets("a grade").Range("j" &
TRow) + (24 - Val2) / 100 + _
(60 - Val3) / 10000 + (60 - Val4) / 1000000

End If
End If


Application.ScreenUpdating = True
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 204
Default error in code

just worked it out. The sheet was protected.

"NDBC" wrote:

not sure if it is important but when you delete times you delete 2 cells
together. columns 11 and 12. Thought I'd better mention this in case it is
effecting something.

"NDBC" wrote:

When i manually delete times (to simulate what would happen if an incorrect
number is typed in and had to be manually corrected) and the column number is
9 the following code gives me an error on the line marked. Can anybody tell
me why. Thanks.



Private Sub Worksheet_Change(ByVal Target As Range)

Application.ScreenUpdating = False


'Column K is column 11
If Target.Column = 11 And Target.Row = 5 Then

TRow = Target.Row
Val1 = Range("G" & TRow).End(xlToRight).Offset(0, -1)
Val2 = Hour(Range("G" & TRow).End(xlToRight).Offset(0, -1))
Val3 = Minute(Range("G" & TRow).End(xlToRight).Offset(0, -1))
Val4 = Second(Range("G" & TRow).End(xlToRight).Offset(0, -1))
val5 = Sheets("timing sheet").Range("c21").Value / 24

If Range("G" & TRow).End(xlToRight).Offset(0, -1).Column < 10 Then

Sheets("a grade").Range("i" & TRow) = 0 'error here

ElseIf Val1 < val5 Then
Sheets("a grade").Range("i" & TRow) = 1000 + Sheets("a grade").Range("j" &
TRow) + (24 - Val2) / 100 + _
(60 - Val3) / 10000 + (60 - Val4) / 1000000
Else
Sheets("a grade").Range("i" & TRow) = 4000 + Sheets("a grade").Range("j" &
TRow) + (24 - Val2) / 100 + _
(60 - Val3) / 10000 + (60 - Val4) / 1000000

End If
End If


Application.ScreenUpdating = True
End Sub

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
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... Corey Excel Programming 4 November 25th 06 04:57 AM
OnTime code error "can't execute code in break mode" tskogstrom Excel Programming 1 September 8th 06 10:29 AM
Error in Excel VBA Code (Error 91) dailem Excel Programming 1 August 25th 06 03:45 PM
How can I still go to the error-code after a On Error Goto? Michel[_3_] Excel Programming 2 May 4th 04 04:21 AM
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) Tim[_36_] Excel Programming 4 April 23rd 04 02:53 AM


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