Compile Error: Ambiguous Name Detected

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Compile Error: Ambiguous Name Detected

Post by ABabeNChrist »

I am getting a Compile Error: Ambiguous Name Detected Worksheet_Change
I am using 2 of

Code: Select all

Private Sub Worksheet_Change(ByVal Target As Range)
Within same sheet. I know this is the problem, but not sure how to resolve it :confused:
Here are the 2 codes that I'm using

Code: Select all

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'Use the Range to select desired cells
    If Not Intersect(Target, Range("E18,E32,E46,E60,E74,H20,H34,H48,H62,H76,H88,H100")) Is Nothing Then
        Target.Select
        AutoFitMergedCellRowHeight
    End If
End Sub
and

Code: Select all

Private Sub Worksheet_Activate()
Me.ScrollArea = Range("go").Address
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
Me.ScrollArea = Range("go").Resize(Range("go").Rows.Count).Address
End Sub

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Compile Error: Ambiguous Name Detected

Post by HansV »

You can't have two procedures (subs) with the same name. Instead, combine the code in one of them and completely delete the other.

For example:

Code: Select all

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'Use the Range to select desired cells
    If Not Intersect(Target, Range("E18,E32,E46,E60,E74,H20,H34,H48,H62,H76,H88,H100")) Is Nothing Then
        Target.Select
        AutoFitMergedCellRowHeight
    End If
    Me.ScrollArea = Range("go").Resize(Range("go").Rows.Count).Address
End Sub
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Compile Error: Ambiguous Name Detected

Post by ABabeNChrist »

WAAAA LAAA
Thank You HansV

Updated: It didn't work at first, until I added

Code: Select all

Private Sub Worksheet_Activate()
Me.ScrollArea = Range("Name Range Here").Address
End Sub
Now it works great, thanks