Hello everyone,
I am looking for help with a VBA Worksheet Change Event.
The following code worked flawlessly until I attempted to insert a row at row 21. It is designed to activate code to display other sheets that are related to the process that is selected when the dropdown is changed in cell A1 and I thought I had error issues handled. I am able to insert text in other cells, choose dropdown selections in data validated cells, all without issue. I am confused as to why trying to insert a row somewhere other than the designated trigger cell (A1) is producing this error (Runtime error '13': Type mismatch). The error occurs at the line stating:
If Target = Range ("A1") Then
This workbook is in Excel 2010 running on Windows 7. The subroutine is in the Sheet1 worksheet I would greatly appreciate any help that someone might offer; so far I have not found any information about why this might happen.
The complete subroutine is as follows:
Private Sub Worksheet_Change(ByVal Target As Range)
'This subroutine determines if a change has been made to the LOB Process drop down on cell A1
'and deletes the existing "Scorecard Rules" worksheet, if it exists
'Screen updating and Display Alerts are turned off to speed up process
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Determine if change was made to cell A1
If Target = Range("A1") Then
'Error handling code is employed if there is no Sheet named "Scorecard Rules" found
On Error GoTo NotFound
'If a Sheet named "Scorecard Rules" already exists it is deleted
Sheets("Scorecard Rules").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Reporting").Select
'Error handling code
NotFound:
Sheets("Reporting").Select
'Once there is no "Scorecard Rules" sheet the IDScrCrd subroutine (Module 1) is called
' to generate the correct sheet which corresponds to the LOB Process chosen in cell A1
IDScrCrd
End If
'Turn the Display Alerts and ScreenUpdating function back on
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
I am looking for help with a VBA Worksheet Change Event.
The following code worked flawlessly until I attempted to insert a row at row 21. It is designed to activate code to display other sheets that are related to the process that is selected when the dropdown is changed in cell A1 and I thought I had error issues handled. I am able to insert text in other cells, choose dropdown selections in data validated cells, all without issue. I am confused as to why trying to insert a row somewhere other than the designated trigger cell (A1) is producing this error (Runtime error '13': Type mismatch). The error occurs at the line stating:
If Target = Range ("A1") Then
This workbook is in Excel 2010 running on Windows 7. The subroutine is in the Sheet1 worksheet I would greatly appreciate any help that someone might offer; so far I have not found any information about why this might happen.
The complete subroutine is as follows:
Private Sub Worksheet_Change(ByVal Target As Range)
'This subroutine determines if a change has been made to the LOB Process drop down on cell A1
'and deletes the existing "Scorecard Rules" worksheet, if it exists
'Screen updating and Display Alerts are turned off to speed up process
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Determine if change was made to cell A1
If Target = Range("A1") Then
'Error handling code is employed if there is no Sheet named "Scorecard Rules" found
On Error GoTo NotFound
'If a Sheet named "Scorecard Rules" already exists it is deleted
Sheets("Scorecard Rules").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Reporting").Select
'Error handling code
NotFound:
Sheets("Reporting").Select
'Once there is no "Scorecard Rules" sheet the IDScrCrd subroutine (Module 1) is called
' to generate the correct sheet which corresponds to the LOB Process chosen in cell A1
IDScrCrd
End If
'Turn the Display Alerts and ScreenUpdating function back on
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub