I would like to start by saying i am pretty much a novice on this stuff so the coding is pretty clunky.
I have a workbook with multiple tabs. Each worksheet can have 2 or many rows and 1 or many values in the invoice number field. In each worksheet, I need to document each invoice number and the amount to be paid. I have the below 2 macros that can do the job but I haven't been able to figure out how to make the paste location dependent on the location of the last populated row.
Thanks in advance.
Sub GettingInvoiceNos1()
'
' GettingInvoiceNos1 Macro
Dim Wks As Worksheet
For Each Wks In ActiveWorkbook.Worksheets
With Wks
Select Case LCase(.Name)
Case Is = "Invoice"
'do nothing
Case Else
'in case you just used the activesheet in your existing code
.Select
Call GettingInvoiceNos2
End Select
End With
Next Wks
End Sub
Sub GettingInvoiceNos2()
'
' GettingInvoiceNos2 Macro
'
'
Dim LastRow As Long
LastRow = Cells(Rows.Count, "af").End(xlUp).Row
Columns("AF:AF").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _
"AF290"), Unique:=True
Range("AF1").Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Range("AG291").Select
ActiveCell.FormulaR1C1 = "=SUMIF(R2C[-1]:R[-4]C[-1],RC[-1],R2C[3]:R[-4]C[3])"
Selection.NumberFormat = "$#,##0.00"
Selection.AutoFill Destination:=Range("AG291:AG293")
Range("AG291:AG293").Select
Range("AG293").Select
Selection.End(xlDown).Select
Selection.End(xlUp).Select
Range("AG295").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-4]C:R[-1]C)"
Range("AG296").Select
ActiveWindow.SmallScroll Down:=-12
End Sub
Bookmarks