Hi!
I have a vba that works when there are multiple line items. But when there is only one line item my macro debugs.
Can someone assist?
I have a vba that works when there are multiple line items. But when there is only one line item my macro debugs.
Can someone assist?
VBA Code:
Sub Redemption()
Dim LR As Long
Dim LastRow As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Sheets("AMT").Select
Range("B2:B24").Copy
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("C2").FormulaArray = "=B2*-1"
Range("C2").AutoFill Range("C2:C24" & Range("A" & Rows.Count).End(xlUp).Row)
Range("A2:C24").Sort Key1:=Range("B2"), Order1:=xlAscending
Sheets("AMT").Select
Range("A1").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$C$24").AutoFilter Field:=2, Criteria1:="<0"
Range("B2:B" & LastRow).SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("SELL_Jrnl").Select
Range("D4").PasteSpecial Paste:=xlPasteValues
Sheets("AMT").Select
Range("B2:B" & LastRow).SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("SELL_Jrnl").Select
Range("E4").PasteSpecial Paste:=xlPasteValues
Sheets("AMT").Select
Range("A2:A" & LastRow).SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("SELL_Jrnl").Select
Range("A4").PasteSpecial Paste:=xlPasteValues
Range("B4").Select
ActiveCell.Value2 = "margin"
Range("B4").AutoFill Range("B4:B" & Range("D" & Rows.Count).End(xlUp).Row)
Sheets("AMT").Select
Range("C2:C" & LastRow).SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("SELL_Jrnl").Select
Range("D4").End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("AMT").Select
Range("C2:C" & LastRow).SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets("SELL_Jrnl").Select
Range("E4").End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("C4").Select
ActiveCell.Value2 = "USD"
Range("C4").AutoFill Range("C4:C" & Range("D" & Rows.Count).End(xlUp).Row)
Range("F4").Select
ActiveCell.Value2 = "ID"
Range("F4").AutoFill Range("F4:F" & Range("D" & Rows.Count).End(xlUp).Row)
Range("G4").Select
ActiveCell.Value2 = "261941306"
Range("G4").AutoFill Range("G4:G" & Range("D" & Rows.Count).End(xlUp).Row)
Range("H4").Select
ActiveCell.Value2 = "USD"
Range("H4").AutoFill Range("H4:H" & Range("D" & Rows.Count).End(xlUp).Row)
Range("I4").Select
ActiveCell.Value2 = "USA"
Range("I4").AutoFill Range("I4:I" & Range("D" & Rows.Count).End(xlUp).Row)
Sheets("SELL_Jrnl").Select
Range("C4").Select
Selection.End(xlDown).Select
ActiveCell.Select
ActiveCell.Offset(0, -2).Select
ActiveCell.Value2 = "XXX123"
Selection.Copy
Range(Selection, Selection.End(xlUp)).Select
Selection.Offset(1, 0).Select
ActiveSheet.Paste
Range("B4").Select
ActiveCell.Value2 = "mm"
Range("B4").AutoFill Range("B4:B" & Range("D" & Rows.Count).End(xlUp).Row)
End Sub