ThrottleWorks
Excel Ninja
Hi,
I am using below code to find headers in the worksheet.
There are more than 10 worksheets in the file that is why am using below Function and Sub to find headers in the worksheet.
In one of the worksheet, there are more than 150 headers to be searched, in this scenario code is taking time to get complete or gets hang.
Can anyone please suggest me how to resolve this.
PS - around 3 minutes to complete 150 headers.
I am using below code to find headers in the worksheet.
There are more than 10 worksheets in the file that is why am using below Function and Sub to find headers in the worksheet.
In one of the worksheet, there are more than 150 headers to be searched, in this scenario code is taking time to get complete or gets hang.
Can anyone please suggest me how to resolve this.
PS - around 3 minutes to complete 150 headers.
Code:
Public Function GetHeaderPos(wks As Worksheet, sHeaderName As String) As Integer
Dim rFound As Range
With wks
Set rFound = .Cells.Find(sHeaderName, .Range("A1"), xlValues, xlWhole, xlByColumns, xlNext)
If Not rFound Is Nothing Then
GetHeaderPos = rFound.Column
Else
GetHeaderPos = 0
End If
End With
End Function
Sub Check_Headers_01()
Dim My_Column As Long
Dim MacroBook As Workbook
Dim Map_Sht As Worksheet
Dim TempRng As Range
Dim TRng As Range
Dim TempLr As Long
Set MacroBook = ThisWorkbook
Set Map_Sht = MacroBook.Worksheets("Mapping")
'Bk_Template.Activate
'Sht_TMPLT_01.Select
TempLr = Map_Sht.Range("E" & Rows.Count).End(xlUp).Row 'Workings_FO Book Not in Mapping
Set TempRng = Map_Sht.Range("E2:E" & TempLr)
For Each TRng In TempRng
My_Column = 0
My_Column = GetHeaderPos(Sht_TMPLT_01, TRng.Value)
If My_Column = 0 Then MsgBox "Header '" & TRng & "'" & " is not found in tab Name '" & Sht_TMPLT_01.Name & "'" & ", please check and try again": Exit Sub
Next TRng
End Sub
Last edited: