main()
set og_NameRng = rRng
If CorrectRangeForHeaderRows(rRng) Then
If CorrectForTotalRow(rRng) Then
Set og_Rng = rRng
bFound = True
End If
End If
Private Function CorrectRangeForHeaderRows(ByRef rRng As Range) As Boolean
rRng.Select
Dim lCorrection As Long: lCorrection = 0
Dim vVar As Variant
ActiveSheet.rRng.Offset(-(lCorrection + 1)).Range(Cells(1, 1), Cells(1, ActiveSheet.rRng.Columns.Count)).Select
vVar = Application.Match("", ActiveSheet.rRng.Offset(-(lCorrection + 1)).Range(Cells(1, 1), Cells(1, ActiveSheet.rRng.Columns.Count)), 0)
If Not IsError(Application.Match("", ActiveSheet.rRng.Offset(-(lCorrection + 1)).Range(Cells(1, 1), Cells(1, ActiveSheet.rRng.Columns.Count)), 0)) Then _
Debug.Print vVar
CorrectRangeForHeaderRows = True
Set rRng = rRng.Resize(lCorrection)
End Function
Private Function CorrectForTotalRow(ByRef rRng As Range) As Boolean
'The problem is that the position we want to search for do not have content in first Column but later
rRng.Select
Dim lCorrection As Long: lCorrection = rRng.Rows.Count
Dim vVar As Variant
ActiveSheet.rRng.Offset(lCorrection - 1).Range(Cells(1, 1), Cells(1, ActiveSheet.rRng.Columns.Count)).Select
vVar = Application.Match("", ActiveSheet.rRng.Offset(lCorrection - 1).Range(Cells(1, 1), Cells(1, ActiveSheet.rRng.Columns.Count)), 0)
If Not IsError(Application.Match("", ActiveSheet.rRng.Offset(lCorrection - 1).Range(Cells(1, 1), Cells(1, rRng.Columns.Count)), 0)) Then _
Debug.Print vVar
Set rRng = rRng.Resize(lCorrection)
rRng.Select
CorrectForTotalRow = True
I just want to let you know, that this is only some test code to find out how it works, more testing and error-checking has to come
I'will just tell you that I have to leave now and will be back tomorow, but I hope you have a kind of solution to the problem. I tested my self and got to the errormessage 2042 and might be I have to add sheetname
Thanks.