Jump to cell after clicking message box ok

kamranyd

Board Regular
Joined
Apr 24, 2018
Messages
152
Office Version
  1. 2021
Platform
  1. Windows
These codes search quot no. and show complete quot details, if quot is not found message box appear, after clicking message box ok button it should got back to G3 cell. Now if the quot not found it dont select G3 cell. if quot is found thn it select G3 cell.

VBA Code:
Sub search_quot()
    Dim Quot_No As String, Fnd As Range, Ws1 As Worksheet, Ws2 As Worksheet, FileNameRef As String, X As Long, Y As Long: Y = 17
    
    Sheets("Quot").Unprotect
    Application.ScreenUpdating = False
    
    Set Ws1 = Sheets("database")
    Set Ws2 = Sheets("QUOT")
    
    FileNameRef = Range("G3").Value
    
    Set Fnd = Ws1.Range("A:A").Find(Ws2.Range("G3").Value, , , xlWhole, , , , , False)
    If Fnd Is Nothing Then MsgBox "Quotation Number [-]> " & FileNameRef & " <[-]" & vbNewLine & "Not found in Quotation Database.", vbExclamation, "Quote Search ERROR":  Exit Sub
    
With Ws2
        .Range("G4").Value = Fnd.Offset(, 1).Value
        .Range("C9").Value = Fnd.Offset(, 138).Value
        .Range("C8").Value = Fnd.Offset(, 2).Value
        .Range("C9").Value = Fnd.Offset(, 3).Value
        .Range("G5").Value = Fnd.Offset(, 140).Value
        .Range("G6").Value = Fnd.Offset(, 141).Value
        .Range("G7").Value = Fnd.Offset(, 142).Value
        .Range("F66").Value = Fnd.Offset(, 7).Value
        For X = 8 To 137 Step 4
            .Range("A" & Y).Value = Fnd.Offset(, X).Value
            .Range("B" & Y).Value = Fnd.Offset(, X + 1).Value
            .Range("E" & Y).Value = Fnd.Offset(, X + 2).Value
            .Range("F" & Y).Value = Fnd.Offset(, X + 3).Value
            Y = Y + 1
        Next X
End With
     Range("G3").Select
     ActiveWindow.ScrollRow = 1
    Sheets("Quot").Protect AllowFormattingCells:=True
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Maybe this:
VBA Code:
Sub search_quot()
    Dim Quot_No As String, Fnd As Range, Ws1 As Worksheet, Ws2 As Worksheet, FileNameRef As String, X As Long, Y As Long: Y = 17
    
    Sheets("Quot").Unprotect
    Application.ScreenUpdating = False
    
    Set Ws1 = Sheets("database")
    Set Ws2 = Sheets("QUOT")
    
    FileNameRef = Range("G3").Value
    
    Set Fnd = Ws1.Range("A:A").Find(Ws2.Range("G3").Value, , , xlWhole, , , , , False)
    If Fnd Is Nothing Then MsgBox "Quotation Number [-]> " & FileNameRef & " <[-]" & vbNewLine & "Not found in Quotation Database.", vbExclamation, "Quote Search ERROR": Range("G3").Select: Exit Sub
    
With Ws2
        .Range("G4").Value = Fnd.Offset(, 1).Value
        .Range("C9").Value = Fnd.Offset(, 138).Value
        .Range("C8").Value = Fnd.Offset(, 2).Value
        .Range("C9").Value = Fnd.Offset(, 3).Value
        .Range("G5").Value = Fnd.Offset(, 140).Value
        .Range("G6").Value = Fnd.Offset(, 141).Value
        .Range("G7").Value = Fnd.Offset(, 142).Value
        .Range("F66").Value = Fnd.Offset(, 7).Value
        For X = 8 To 137 Step 4
            .Range("A" & Y).Value = Fnd.Offset(, X).Value
            .Range("B" & Y).Value = Fnd.Offset(, X + 1).Value
            .Range("E" & Y).Value = Fnd.Offset(, X + 2).Value
            .Range("F" & Y).Value = Fnd.Offset(, X + 3).Value
            Y = Y + 1
        Next X
End With
     Range("G3").Select
     ActiveWindow.ScrollRow = 1
    Sheets("Quot").Protect AllowFormattingCells:=True
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Maybe this:
VBA Code:
Sub search_quot()
    Dim Quot_No As String, Fnd As Range, Ws1 As Worksheet, Ws2 As Worksheet, FileNameRef As String, X As Long, Y As Long: Y = 17
   
    Sheets("Quot").Unprotect
    Application.ScreenUpdating = False
   
    Set Ws1 = Sheets("database")
    Set Ws2 = Sheets("QUOT")
   
    FileNameRef = Range("G3").Value
   
    Set Fnd = Ws1.Range("A:A").Find(Ws2.Range("G3").Value, , , xlWhole, , , , , False)
    If Fnd Is Nothing Then MsgBox "Quotation Number [-]> " & FileNameRef & " <[-]" & vbNewLine & "Not found in Quotation Database.", vbExclamation, "Quote Search ERROR": Range("G3").Select: Exit Sub
   
With Ws2
        .Range("G4").Value = Fnd.Offset(, 1).Value
        .Range("C9").Value = Fnd.Offset(, 138).Value
        .Range("C8").Value = Fnd.Offset(, 2).Value
        .Range("C9").Value = Fnd.Offset(, 3).Value
        .Range("G5").Value = Fnd.Offset(, 140).Value
        .Range("G6").Value = Fnd.Offset(, 141).Value
        .Range("G7").Value = Fnd.Offset(, 142).Value
        .Range("F66").Value = Fnd.Offset(, 7).Value
        For X = 8 To 137 Step 4
            .Range("A" & Y).Value = Fnd.Offset(, X).Value
            .Range("B" & Y).Value = Fnd.Offset(, X + 1).Value
            .Range("E" & Y).Value = Fnd.Offset(, X + 2).Value
            .Range("F" & Y).Value = Fnd.Offset(, X + 3).Value
            Y = Y + 1
        Next X
End With
     Range("G3").Select
     ActiveWindow.ScrollRow = 1
    Sheets("Quot").Protect AllowFormattingCells:=True
    Application.ScreenUpdating = True
End Sub
thnx
 
Upvote 0

Forum statistics

Threads
1,223,880
Messages
6,175,154
Members
452,615
Latest member
bogeys2birdies

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