Merging subroutines

wsautrey

New Member
Joined
Apr 2, 2011
Messages
21
Need assistance merging the 2 routines below to avoid duplication of Private Sub Worksheet_Change(ByVal Target As Range)
Excel 2003






Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Row = D010.Range("IncidentDes").Row And Target.Column = D010.Range("IncidentDes").Column Then
If Len(Target.Value) > gciMaxTxtLen Then
Load frmTextEntry
frmTextEntry.Show
D010.Range("SC1").Select
End If
End If

End Sub

_________________________________________________________________
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$3" Then
Application.EnableEvents = False
If Target.Value <> "Drilling" Then
With Range("C3")
.Value = "HLV"
With .Validation
.Delete
.Add Type:=xlValidateTextLength, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlEqual, Formula1:="0"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = "Leave cell blank"
.ShowInput = False
.ShowError = True
End With
End With
Else
With Range("C3")
.Value = ""
With .Validation
.Delete
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlEqual, Formula1:="=Class"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = "Select from the list"
.ShowInput = False
.ShowError = True
End With
End With
End If
End If
Application.EnableEvents = True
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Maybe like this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = D010.Range("IncidentDes").Row And Target.Column = D010.Range("IncidentDes").Column Then
    If Len(Target.Value) > gciMaxTxtLen Then
        Load frmTextEntry
        frmTextEntry.Show
        D010.Range("SC1").Select
    End If
ElseIf Target.Address = "$B$3" Then
    Application.EnableEvents = False
    If Target.Value <> "Drilling" Then
        With Range("C3")
            .Value = "HLV"
            With .Validation
                .Delete
                .Add Type:=xlValidateTextLength, _
                AlertStyle:=xlValidAlertStop, _
                Operator:=xlEqual, Formula1:="0"
                .IgnoreBlank = True
                .InCellDropdown = True
                .InputTitle = ""
                .ErrorTitle = ""
                .InputMessage = ""
                .ErrorMessage = "Leave cell blank"
                .ShowInput = False
                .ShowError = True
            End With
        End With
    Else
        With Range("C3")
            .Value = ""
            With .Validation
                .Delete
                .Add Type:=xlValidateList, _
                AlertStyle:=xlValidAlertStop, _
                Operator:=xlEqual, Formula1:="=Class"
                .IgnoreBlank = True
                .InCellDropdown = True
                .InputTitle = ""
                .ErrorTitle = ""
                .InputMessage = ""
                .ErrorMessage = "Select from the list"
                .ShowInput = False
                .ShowError = True
            End With
        End With
    End If
    Application.EnableEvents = True
End If
End Sub

Please use code tags when posting code:

[code]
code here
[/code]
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,331
Members
452,907
Latest member
Roland Deschain

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