VBA - need assistance with macro regarding one value vs multiple

jwoo89

New Member
Joined
Jan 5, 2021
Messages
32
Office Version
  1. 2016
Platform
  1. Windows
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?

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
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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 assume that what you mean by "my macro debugs" is that a runtime error occurred? Keep in mind that when you ask for help with an error, but do in include any information about the error, a lot of people will skip over your post. When you need help with an error, in addition to your code, you should always include at least these three pieces of information in your post:

1. The error number (example: Run Time Error '91')
2. The error description (example: "Object Variable or With Block not Set")
3. The line of code where the error occurs (example: MsgBox "Used range is: " & WS.UsedRange.Address)

1668717587119.png
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top