I'm creating some code to better keep track of expenses. One of the macros is meant to load fixed expenses from another worksheet, only when the amounts are not empty and, in the case of credits, only if there's still pending payments.
My code is as follows:
Sub CargarFijos()
ActiveSheet.Range("J4").Select
If Not ActiveSheet.Previous Is Nothing Then
If Not ActiveSheet.Previous.Range("C12") Is Nothing Then
If Not IsEmpty(ActiveSheet.Previous.Range("C12")) Then
ActiveCell.Text = "Tarjeta de Credito"
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = ActiveSheet.Previous.Range("C12").Value
ActiveCell.Offset(1, -1).Select
End If
End If
End If
If Not IsEmpty(ActiveCell) Then
ActiveCell.Offset(1, 0).Select
End If
If Not Worksheets("Fijos") Is Nothing Then
For Each c In Worksheets("Fijos").Range("A2:A40").Cells
If Not c Is Nothing Then
If Not IsEmpty(c.Offset(0, 1)) And Not c.Offset(0, 1) Is Nothing Then
If IsEmpty(c.Offset(0, 2)) And Not c.Offset(0, 2) Is Nothing Then
ActiveCell.Text = c.Text
ActiveCell.Offset(0, 1).Value = c.Offset(0, 1).Value
ActiveCell.Offset(1, 0).Select
ElseIf Not c.Offset(0, 2) Is Nothing And c.Offset(0, 2).Value > 0 Then
ActiveCell.Text = c.Text
ActiveCell.Offset(0, 1).Value = c.Offset(0, 1).Value
c.Offset(0, 2).Value = c.Offset(0, 2).Value - 1
ActiveCell.Offset(1, 0).Select
End If
End If
End If
Next
End If
End Sub
My worksheet "Fijos" is where I have my fixed expenses. On column A I have the descriptions, on column B I have the amount to be payed, and on column C I have the pending payments.
The idea is that I run along the A column, check the B and C column and, if there's an amount to pay on column B and pending payments (or empty) on C, I add the amount of B on my ActiveSheet.
On my ActiveSheet, column J is the description of the expenses and column K is the amount.
Whenever I execute the Macro, it says "Object Required" but doesn't say which line the error occurred at.
Any ideas? I only started trying out VBA a few days ago and it's probably a newbie mistake.