Extra row..

Nielinki

New Member
Joined
Mar 3, 2025
Messages
18
Office Version
  1. 365
Platform
  1. Windows
Can someone please help me?
What part of my code is wrong that the first empty row in N is also getting a DBRow number in U after I click Save Order?
Screenshot 2025-03-10 164600.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("U16:U999").Find("T")
    If Not TotalRange Is Nothing Then .Range("O" & TotalRange.Row & ":U" & 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("P13").Value 'New Order Number
        Else: 'Existing Order
            OrderRow = Range("B3").Value 'Order Row
            
    End If
        
        ORDERS.Range("B" & OrderRow).Value = Date 'Date
        ORDERS.Range("C" & OrderRow).Value = Time 'Time
        ORDERS.Range("D" & OrderRow).Value = .Range("P11").Value 'Register
        ORDERS.Range("E" & OrderRow).Value = .Range("W27").Value 'Total
        ORDERS.Range("F" & OrderRow).Value = .Range("W28").Value 'Payment
        ORDERS.Range("G" & OrderRow).Value = .Range("B12").Value 'PayType
        '.Range("O12").Value = Now 'Current Date
        
        'Enter Item Details
        For ItemRow = 16 To LastRow
            If Range("U" & ItemRow).Value = Empty Then 'New Item
                ItemDBRow = ORDERITEMS.Range("A9999").End(xlUp).Row + 1 'First Available Row
                ORDERITEMS.Range("A" & ItemDBRow).Value = .Range("P13").Value 'Order ID
                ORDERITEMS.Range("G" & ItemDBRow).Value = ItemRow
                ORDERITEMS.Range("H" & ItemDBRow).Value = ItemDBRow
                .Range("U" & ItemRow).Value = ItemDBRow
            Else: 'Existing Item
                ItemDBRow = .Range("U" & ItemRow).Value 'Item DB Row
            End If
            
            ORDERITEMS.Range("C" & ItemDBRow).Value = .Range("L" & ItemRow).Value 'ItemType
            ORDERITEMS.Range("B" & ItemDBRow).Value = .Range("M" & ItemRow).Value 'ItemID
            ORDERITEMS.Range("D" & ItemDBRow).Value = .Range("N" & ItemRow).Value 'Product Name
            ORDERITEMS.Range("E" & ItemDBRow).Value = .Range("O" & ItemRow).Value 'Quantity
            ORDERITEMS.Range("F" & ItemDBRow).Value = .Range("P" & ItemRow).Value 'Price
        Next ItemRow
        
    .Shapes("DeleteIcon").Visible = msoFalse
    .Shapes("IncreaseIcon").Visible = msoFalse
    .Shapes("DecreaseIcon").Visible = msoFalse
    .Shapes("PAIDStamp").Visible = msoTrue
    .Shapes("DISCOUNTStamp").Visible = msoFalse

End With
End Sub
 
I don't understand your question.
Can you actually post the pertinent section of your data in a manner that which we can copy, explain exactly what is happening (walk us through an example), and explain what you actually want to happen in that particular example?

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
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