Solved

MS Excel 2010/2013

Posted on 2014-01-11
7
243 Views
Last Modified: 2014-01-11
Hi,
I have an active X combo box on a worksheet that moves the cursor to the correct cell when the user selects an item from the list.
The problem I have is that whenever a cell is changed in any other worksheet, the code behind the combo box runs and the user is taken to the sheet with the combo box on it, even though nothing has changed in the combo box! I have tried adding "thisworkbook.sheets" etc but to no avail.

this is the simple code behind the active X combo box;

Private Sub cboCust_Change()
Dim c As Range
    For Each c In Range("A4:A500")
        If c.Value = cboCust.Value Then
            Application.Goto c, Scroll:=True
            c.select
            Exit Sub
        End If
    Next
End Sub

Any help is appreciated.
Thanks
0
Comment
Question by:Stephen Byrom
  • 5
7 Comments
 
LVL 15

Expert Comment

by:gplana
Comment Utility
I think you can avoid this problem just by adding an if to execute the code only if the currentcell is the cell you want.

something like:

Private Sub cboCust_Change()
Dim c As Range
   if activeCell.row=3 and activeCell.column=1 then
    For Each c In Range("A4:A500")
        If c.Value = cboCust.Value Then
            Application.Goto c, Scroll:=True
            c.select
            Exit Sub
        End If
    Next
   end if
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:Stephen Byrom
Comment Utility
Thanks GP but I tried that earlier, although with active sheet...

Dim c As Range
   If ActiveSheet = Sheets("NonAuto") Then
    For Each c In Range("A4:A500")
        If c.Value = cboCust.Value Then
            Application.Goto c, Scroll:=True
            c.Select
            Exit Sub
        End If
    Next
   End If

but that didn't work either.

I have added a snapshot of the workbook to make it easier to see what the problem is
Call-Offs.xlsm
0
 
LVL 26

Accepted Solution

by:
MacroShadow earned 500 total points
Comment Utility
You were missing the .name

Private Sub cboCust_Change()
    Dim c As Range
    If ActiveSheet.Name = Sheets("NonAuto").Name Then
        For Each c In Range("A4:A500")
            If c.Value = cboCust.Value Then
                Application.GoTo c, Scroll:=True
                c.Select
                Exit Sub
            End If
        Next
    End If
End Sub

Open in new window

0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Author Comment

by:Stephen Byrom
Comment Utility
Got it.
Seems a bit clumsy but this works..
Private Sub cboCust_Change()
If ActiveSheet.Name = "NonAuto" Then
Dim c As Range
    For Each c In Range("A4:A500")
        If c.Value = cboCust.Value Then
            Application.Goto c, Scroll:=True
            c.Select
            Exit Sub
        End If
    Next
End If
End Sub
0
 
LVL 1

Author Comment

by:Stephen Byrom
Comment Utility
I've requested that this question be closed as follows:

Accepted answer: 0 points for olorin57's comment #a39773497

for the following reason:

trial and error for about two hours
0
 
LVL 1

Author Comment

by:Stephen Byrom
Comment Utility
wow,
I think we posted at the same time.
In fact if I look at the posting times I was a minute later than MacroShadow, so if a moderator wants to award the points to him/her, then I don't mind at all.
0
 
LVL 1

Author Closing Comment

by:Stephen Byrom
Comment Utility
Thanks for your time
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now