I am beginner with VBA and I need your help for some issues.
You will find my code below. I get a compile error with Mtable.
Thanks.
Sub GatheringofExpense()
Dim Branches As Worksheet
Dim Final As Worksheet
Dim i As Integer
Dim lrow As Range
Dim lcol As Range
Set Branches = Worksheets("Branches")
Set Final = Worksheets("Final")
'Defining last row and last column in the table for our Array
lrow = Range("A1000000").End(xlUp).Row
lcol = Range("XFD4").End(xlToLeft).Column
Mtable = Range(Cells(4, 1), Cells(lrow, lcol)) 'Assigning array for table
For i = 1 To UBound(Mtable, 1)
If Branches.Range("A" & i)="Barda" And Range("B" & i)="Fuzuli" Then
Range("A" & i).End(xlToRight).Copy
Final.Range("A1000000").End(xlUp).Offset(1, 0).PasteSpecial xlPasteAll
End If
Next i
End Sub
Mtable. Good practice is to useOption Explicitat the top of all of your modules. In any event -- you have declaredlrowandlcolto beRangebut are treating them as if they wereLong. Also -- don't useIntegerfor row indices. It isn't large enough of a data type for all possible rows. UseLonginstead.Mtablethat was of an inconsistent type.