Code in use selects cell but i am unable to then click out of cell

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
On my worksheet called INV i use this code shown below which looks at the value in cell G13, then opens worksheet called DATABASE & selects the cell in column A that matches.
This works fine BUT if i want to use the arrow on the keyboard to then select cell in column B C D etc etc i see that i cant move from the cell in column A

The only way i can do it is by using my left mouse button.

Do you see why Thanks.


Rich (BB code):
Private Sub GoToCustomer_Click()
    Dim FindString As String
    Dim rng As Range
    If Range("G13") = "" Then
    MsgBox "NO NAME SELECTED IN THE CUSTOMER DETAILS SECTION", vbCritical, "NO CUSTOMER SELECTED MESSAGE"
    End If
    
    FindString = Range("G13").Value
    If Trim(FindString) <> "" Then
        With Sheets("DATABASE").Range("A:A")
        Application.EnableEvents = False

            Set rng = .Find(What:=FindString, _
                            After:=.Cells(.Cells.Count), _
                            LookIn:=xlValues, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, _
                            MatchCase:=False)
                            If Not rng Is Nothing Then
                Application.Goto rng, True
                ActiveCell.Interior.Color = vbRed
                Application.EnableEvents = True
            Else
                MsgBox "CUSTOMER NOT FOUND"
            End If
        End With
    End If
End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
The only bad thing I see is that you are not enabling the events if it does not find the data.

Look at the improvements to your macro:
Rich (BB code):
Private Sub GoToCustomer_Click()
  Dim FindString As String
  Dim rng As Range
  
  FindString = Range("G13").Value       'Use the variable from the beginning.
  
  If FindString = "" Or Trim(FindString) = "" Then
    MsgBox "NO NAME SELECTED IN THE CUSTOMER DETAILS SECTION", vbCritical, "NO CUSTOMER SELECTED MESSAGE"
  End If
  
  With Sheets("DATABASE").Range("A:A")
    Application.EnableEvents = False
    
    Set rng = .Find(What:=FindString, After:=.Cells(.Cells.Count), LookIn:=xlValues, _
              LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
    If Not rng Is Nothing Then
      Application.Goto rng, True
      ActiveCell.Interior.Color = vbRed
    Else
      MsgBox "CUSTOMER NOT FOUND"
    End If
  
    Application.EnableEvents = True       'out of the End If
 
  End With
End Sub

You have another macro running that is turning off the screen with Application.ScreenUpdating = False, if so, put Application.ScreenUpdating = True at the end of the macro
 
Upvote 0
Solution

Forum statistics

Threads
1,215,097
Messages
6,123,076
Members
449,094
Latest member
mystic19

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