How to convert macro to VBA

Sheets(“Unprocessed AP Invoice Liabilit”).Select
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
lr = Cells(Rows.Count, 1).End(xlUp).Row
Range(“L2”).Select
ActiveCell.FormulaR1C1 = “=RC[-6]-TODAY()”
Range(“L3”).Select
Columns(“L:L”).EntireColumn.AutoFit
Range(“L2”).Select
ActiveCell.FormulaR1C1 = “=TODAY()-RC[-6]”
Range(“L2”).Select
Selection.NumberFormat = “0”
Range(“M2”).Select
ActiveCell.FormulaR1C1 = _
“=IF(RC[-1]<=7,”“0-7"”,IF(RC[-1]<=14,““8-14"”,IF(RC[-1]<=29,”“15-29"”,IF(RC[-1]>30,“”>30"“,”“NA”“))))”
Range(“L2:M” & lr).Select
Selection.FillDown
Range(“A1”).Select
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False

want to convert to VBA, also VBA macro is enabled but i can’t see Developer option in excel, how do it
Regards

@RAKESH_KUMAR_Tiwari

  1. Open the workbook containing the macro you want to convert.
  2. Press ALT + F11 to open the VBA editor.
  3. In the VBA editor, locate the project window on the left-hand side of the screen.
  4. Expand the project containing the macro you want to convert.
  5. Locate the module containing the macro you want to convert.
  6. Double-click the module to open it.
  7. Select the macro code you want to convert.
  8. Right-click the selected code and choose “Copy”.
  9. Create a new module by right-clicking on the project window and selecting “Insert” and then “Module”.
  10. In the new module, right-click and select “Paste” to paste the copied macro code.
  11. Review the code and make any necessary adjustments to ensure that it works correctly within the VBA environment.
  12. Save the workbook with the new VBA code.

Hi

Here’s the VBA code that should be equivalent to the Excel VBA code you provided:

Sub ProcessAPInvoices()

Sheets("Unprocessed AP Invoice Liabilit").Select

If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False

Dim lr As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row

Range("L2").Select
ActiveCell.FormulaR1C1 = "=RC[-6]-TODAY()"

Range("L3").Select
Columns("L:L").EntireColumn.AutoFit

Range("L2").Select
ActiveCell.FormulaR1C1 = "=TODAY()-RC[-6]"
Selection.NumberFormat = "0"

Range("M2").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-1]<=7,""0-7"",IF(RC[-1]<=14,""8-14"",IF(RC[-1]<=29,""15-29"",IF(RC[-1]>30,"">30"",""NA""))))"

Range("L2:M" & lr).Select
Selection.FillDown

Range("A1").Select
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False

End Sub

Note that the code assumes that you have a worksheet named “Unprocessed AP Invoice Liabilit” and that it contains data in columns A through M. If any of these assumptions are incorrect, you may need to modify the code accordingly.

The Developer tab may not be visible in Excel by default. Here’s how you can make it visible:

  1. Click on the File tab in the ribbon menu.
  2. Click on Options.
  3. In the Excel Options window, click on Customize Ribbon.
  4. In the right pane, under Customize the Ribbon, select the Developer check box.
  5. Click OK.

Cheers @RAKESH_KUMAR_Tiwari

what is this error while saving it

click “No” and save as “.xlsm” file @RAKESH_KUMAR_Tiwari

@RAKESH_KUMAR_Tiwari

you can save it in text file and can invoke from there using invoke vba

cheers

image
what to put in entry method

i am trying to run VBA manually , i got error

@RAKESH_KUMAR_Tiwari

Give the function or method name in the name field…

Eg:

If the vba is as below then method is test

Function test(Target As String)
 Range(Target).RowHeight = 0.75
End Function

Cheers