Trying to return a row number with find method

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
I am trying to return the row number but it says Run-Time error 91 on the line below...
Any ideas why???

VBA Code:
iRow = .Range("S13:S" & .UsedRange.Rows.Count).Find("GROSS PROFIT ANALYSIS", LookIn:=xlValues, lookat:=xlWhole).Row

Private Sub Fill_Details_to_JobRecord_Click()

    TurnOff
             
                Application.ScreenUpdating = False
              
                  
                        Dim SrcOpen As Workbook
                        Dim Des As Workbook
                        Dim JCM As Worksheet
                        Dim TGSR As Worksheet
                        Dim FilePath As String
                        Dim Filename As String
                        Dim DesDataRange As Range
                        Dim SrcDataRange As Range
                        Dim iRow As Integer
                      
                      
                        FilePath = "\\tgs-srv01\share\ShopFloor\PRODUCTION\JOB BOOK\"
                        Filename = "JOB RECORD SHEET.xlsm"
                      
                        Set JCM = ThisWorkbook.Worksheets("Job Card Master")

                      
                        Set SrcDataRange = JCM.Range("A13").CurrentRegion

                      
'                      On Error GoTo ErrHandler
                       With JCM
                  
                     iRow = .Range("S13:S" & .UsedRange.Rows.Count).Find("GROSS PROFIT ANALYSIS", LookIn:=xlValues, lookat:=xlWhole).Row
                     iRow = iRow + 7

                     End With
                   
                     Set SrcOpen = Workbooks.Open(FilePath & Filename)
                     Set TGSR = SrcOpen.Worksheets("TGS JOB RECORD")
                     Windows("JOB RECORD SHEET.xlsm").Visible = True
                   
                      TGSR.Range("V").Value = WorksheetFunction.VLookup(JCM.Range("G2"), iRow, 22, 0)
                      Range("V").Select
                   
                  
                      SrcOpen.Close
       
'ErrHandler:
'                       If Err = 1004 Then
'                       MsgBox "Fill Job Number in Job Card Master Sheet Cell G2"
'                       End If

TurnOn
End Sub
 
what happens when you unmerge the cells and test it ?
I missed that you mentioned it is in a merged cell.
Merged cells are notorious sources of pain (especially with VBA!), and should really be avoided at ALL costs!
What cells is S159 merged with?
What happens when you unmerge the cell and test the code?
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Sorry I`ve got it to work now by taking used range away. Also, I was using an auto recovered workbook which was messing things up.
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,536
Members
449,037
Latest member
tmmotairi

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