i wrote this 2 functions which returns values of last row and column in worksheet. They are same but returns difrent values. Is it posible to combine them to 1 function in simple way? i think about global variable i_lRow and i_lColumn and assign value into function or do some class for example wsSetting and add properties named lastRow, lastColumn.
Sub testWywolania()
variable = GetMaxLastColumn(ActiveSheet)
variable2 = GetMaxLastRow(ActiveSheet)
MsgBox variable & vbCrLf & variable2
End Sub
Function GetMaxLastRow(ws As Worksheet) As Integer
Dim i_lr As Integer, i_lc As Integer, i_tempLc As Integer, i_assumption As Integer, i_assumptionR As Integer, i_assumptionC As Integer, i_aVal As Integer
Dim r_workRange As Range
i_lc = 0
i_lr = 0
i_assumption = 30
i_aVal = i_assumption
i_assumptionC = i_assumption
i_assumptionR = i_assumption
Do
i = i + 1
Do
j = j + 1
i_tempLc = ActiveSheet.Cells(i, Columns.Count).End(xlToLeft).Column
i_tempLr = ActiveSheet.Cells(Rows.Count, j).End(xlUp).Row
If i_tempLc > i_lc Then i_lc = i_tempLc: i_tempLc = 0
If i_tempLr > i_lr Then i_lr = i_tempLr: i_tempLr = 0
If i >= i_aVal And j >= i_aVal Then
i_assumptionR = i_lr
i_assumptionC = i_lc
End If
Loop While j <= i_assumptionC
Loop While i <= i_assumptionR
GetMaxLastRow = i_lr
End Function
Function GetMaxLastColumn(ws As Worksheet) As Integer
Dim i_lr As Integer, i_lc As Integer, i_tempLc As Integer, i_assumption As Integer, i_assumptionR As Integer, i_assumptionC As Integer, i_aVal As Integer
Dim r_workRange As Range
i_lc = 0
i_lr = 0
i_assumption = 30
i_aVal = i_assumption
i_assumptionC = i_assumption
i_assumptionR = i_assumption
Do
i = i + 1
Do
j = j + 1
i_tempLc = ActiveSheet.Cells(i, Columns.Count).End(xlToLeft).Column
i_tempLr = ActiveSheet.Cells(Rows.Count, j).End(xlUp).Row
If i_tempLc > i_lc Then i_lc = i_tempLc: i_tempLc = 0
If i_tempLr > i_lr Then i_lr = i_tempLr: i_tempLr = 0
If i >= i_aVal And j >= i_aVal Then
i_assumptionR = i_lr
i_assumptionC = i_lc
End If
Loop While j <= i_assumptionC
Loop While i <= i_assumptionR
GetMaxLastColumn = i_lc
End Function

