On Error goto specific cell

Computerman

Board Regular
Joined
Mar 3, 2016
Messages
91
In my spreadsheet there is one place that the user can enter a value that can cause an error. I have created an error handling routine that captures the error and clears out the cell the error occurred in. What I need is to make that cell active. Here is the error handling code I have created:
Code:
ErrorHandler:
MsgBox "arrival Time must be entered with a space between the time and AM or PM. IE 10:00 AM", , "Invalid Arrival time"
Sheet1.Cells(RC, 4).Value = ""
ActiveSheet.Cells(RC, 4).Select
[\code]
RC is set to the current row and column 4 is the cell that the error occurred in. The message box appears, the user clicks OK, the cell contents are cleared but the active cell is not the cell that the error occurred on. I have also tried changing the ActiveSheet to Sheet1 but that did not help.
thanks,
Computerman
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Does activating the sheet do it?

Code:
Sheet1.Activate
Cells(RC, 4).Value = ""
Cells(RC, 4).Select
 
Last edited:
Upvote 0
daverunt,
thank you for the suggestion, but that did not work. One thing I should mention is that the Sub that call the sub that is getting the error, and hence where the error handler is located, has as it's last line:
Code:
ActiveSheet.Cells(RC, 2).Select
[\code]
and that is the cell that is being made active. I think I need to put in some logic so that if an error occurs the active cell will go to the cell that caused the error. I will reply back if that works.

Computerman
 
Upvote 0
RESOLVED
daverunt,
first let me say thank you for trying to assist me with my issue, I do greatly appreciate it. That willingness to helps makes Mr. Excel forum a 'goto' place when I need help with some Excel VBA code that is not doing what I want it to do.

I resolved my issue by not using a 'proper error handling' technique. When I searched for what constitutes a 'proper time' value I ran across a formula that firsts checks that the length of the entered value is greater than zero and then checks that the value is Greater or equal to zero and less than 1. If it is I run my code, if not I bring up a message box that describes the problem, clears out the cell, and puts the focus on that cell. I put the code in the subroutine that creates the ComboBox as that starts the rest of the subroutines that count on that cell having a properly formatted date. Here is the code I am using in case anyone else has this problem:
Code:
 If (Len(Trim(Sheet1.Cells(RC, 4).Value)) > 0 And Sheet1.Cells(RC, 4).Value >= 0 And Sheet1.Cells(RC, 4).Value < 1) Then
        SetTZ
        Module1.StartTimer
        ActiveSheet.Cells(2, 1).Select
    Else
        MsgBox "Arrival Time must be entered as a valid date with a space between the time and AM or PM.      IE: 10:00 AM", , "Invalid Arrival time"
        Sheet1.Cells(RC, 4).Value = ""
        ActiveSheet.Cells(RC, 4).Select
    End If

Computerman
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top