Compile Error..

Nielinki

New Member
Joined
Mar 3, 2025
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hi there (very new to VBA)
When I run the module Save_Order it runs fine but when I add it to the module Next_Order, it gives me a Compile Error..
What am I doing wrong please?

Screenshot 2025-03-06 075959.png
Screenshot 2025-03-06 075218.png


VBA Code:
Option Explicit

Public Sub Save_Order()
Dim LastRow As Long, OrderRow As Long, ItemRow As Long, ItemDBRow As Long, TotalRow As Long
Dim TotalRange As Range

With POS
    If .Range("M16").Value = Empty Then
        MsgBox "Please add at least one item to save this order"
        Exit Sub
    End If
   
    'Clear Total Rows if Existing (Temporarily)
    Set TotalRange = .Range("T16:T999").Find("T")
    If Not TotalRange Is Nothing Then .Range("O" & TotalRange.Row & ":T" & TotalRange.Row + 4).ClearContents
        LastRow = .Range("M16:P70").Find(What:="*", After:=.Range("M16"), Lookat:=xlPart, LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row + 1  'First Avail Row
            If .Range("B3").Value = Empty Then 'New Order
            OrderRow = ORDERS.Range("A9999").End(xlUp).Row + 1 'First Available Row
            ORDERS.Range("A" & OrderRow).Value = .Range("O13").Value 'New Order Number
        Else: 'Existing Order
            OrderRow = Range("B3").Value 'Order Row
    End If
           
        ORDERS.Range("B" & OrderRow).Value = Now 'Date
        ORDERS.Range("C" & OrderRow).Value = .Range("O11").Value 'Register
        .Range("O12").Value = Now 'Current Date/Time
       
    'Add In TotalRange
    Order_AddTotals 'Macro To Add Totals In
    LastRow = .Range("M999").End(xlUp).Row 'Last Row
    ORDERS.Range("D" & OrderRow).Value = .Range("P" & LastRow + 3).Value 'Total
    ORDERS.Range("E" & OrderRow).Value = .Range("P" & LastRow + 4).Value 'Payment
    .Shapes("DeleteIcon").Visible = msoFalse

End With
End Sub

VBA Code:
Option Explicit

Public Sub Next_Order()
With POS
    If .Range("M16").Value <> Empty Then Save_Order 'Save Existing Order
        .Range("B2").Value = .Range("B4").Value 'Set Next Order ID
        .Range("B7,B8,B12,B13,O12,P12,O13,L16:T999").ClearContents
        .Shapes("DeleteIcon").Visible = msoFalse
        .Range("O13").Value = .Range("B2").Value
        .Range("O12").Value = Date 'Set Current Time & Date
        .Range("P12").Value = Time 'Set Current Time & Date
    End With
End Sub
 
Fluff's method is preferable but fully specifying the call will also work:
ie module name + period + procedure name
Rich (BB code):
    If .Range("M16").Value <> Empty Then Save_Order.Save_Order 'Save Existing Order
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

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