Trim Function

Eric Penfold

Active Member
Joined
Nov 19, 2021
Messages
424
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Please could someone help with the Trim Function below.
It says wrong number of arguments?

VBA Code:
Sub Group_OrderNos()

    Dim ws    As Worksheet
    Dim Rng   As Range
    Dim LRow  As Long
    Dim Row   As Long
    Dim Row_1 As Long
    Dim Row_2 As Long
    Dim ct    As Long
    Dim fr    As Long
    Dim i     As Variant
    Dim y     As Variant
   

   
    Set ws = ActiveSheet
   
    Call Duplicate_Delete
   
    If ws.Range("AA1") = "" Then
        ws.Range("AA1") = 1

    LRow = ws.Range("C2").End(xlDown).Row
   
    Set Rng = ws.Range("L2:L" & LRow)
    Rng.Clear
    Rng.Value = "A"
   
        If ws.Name <> "Summary" And ws.Name <> "Trend" And ws.Name <> "Supplier BO" And ws.Name <> "Dif Depot" _
        And ws.Name <> "BO Trend WO" And ws.Name <> "BO Trend WO 2" And ws.Name <> "Different Depot" Then
       
        On Error Resume Next
        ws.Range("A1:H" & LRow).Sort Key1:=Range("C1"), Header:=xlYes, OrderCustom:=1, _
        MatchCase:=False, Orientation:=xlTopToBottom
       
        Application.ScreenUpdating = False
       
        fr = 2
        ct = 1
   
        For Row = 2 To LRow
            If Cells(Row, "C").Value = Cells(Row - 1, "C") Then
                ct = ct + 1
            End If
            If Cells(Row, "C").Value <> Cells(Row + 1, "C") Then
                If ct > 1 Then
                    On Error Resume Next
                    ws.Rows(fr & ":" & Row).Group
                End If
                ct = 1
                fr = Row + 1
            End If
        Next Row
       
   
        With ws
            
              For Row = LRow To 2 Step -1
                If (Trim$(Row, "C") = Trim$(Row - 1, "C")) And _
                    (Trim$(Row, "E") = Trim$(Row - 1, "E")) Then
                        Cells(Row - 1, "G") = Cells(Row, "G") + Cells(Row - 1, "G")
                        Cells(Row, "A").EntireRow.Delete
                   
                    End If
                End If
       
             Next Row
   
           
        MsgBox "OrderNos Group & Duplicate Codes Qty Group Complete!"
           
         .Range("AA1") = ""
        
        End With
   
    End If
End If
 
Last edited by a moderator:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
should be

Code:
If (Trim(Cells(row, "C")) = Trim(Cells(row - 1, "C"))) And _
(Trim(Cells(row, "E")) = Trim(Cells(row - 1, "E"))) Then
 
Upvote 0
Thanks all works.
Please explain to me what i got wrong first time.
 
Upvote 0
Thanks all works.
Please explain to me what i got wrong first time.
You need to define that it was looking at a cell reference IE trim(cells(row,col)) otherwise it assumes trim("text") or trim(variableName)
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

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