1

I'm getting the "user-defined type not defined" error in this line of my code

Sub Customer_Load()

This my code

Option Explicit
Sub Customer_Load()
  Dim CltRow As Long, LastRepRow As Lon, CustCol As Long
  With Sheet1
    If .Range("B6").Value = Empty Then
        MsgBox "Por favor, seleccione un cliente"
        Exit Sub
    End If
    CltRow = .Range("B6").Value
        
        'Clear Existing Data
        .Range("E4:G4,E6:G6,E8:G8,E10:G10,E12:G12,J4:L4, J6:L6,J8:L8,J10:L10,J12:L12").ClearContents 'Clear Customer Cells
        .Range("D17:I45").ClearContents 'Clear All Other Fields
        
        For CustCol = 1 To 12
            .Range(Sheet2.Cells(1, CustCol).Value).Value = Sheet2.Cells(CltRow, CustCol).Value
        Next CustCol
        
        .Shapes("ExistCustGrp").Visible = msoCTrue
        .Shapes("NewCustGrp").Visible = msoFalse
        .Shapes("ExistRepGrp").Visible = msoCTrue
        .Shapes("NewRepBtn").Visible = msoFalse
    End With
End Sub

I saw that a way to fix this error is by adding the available references, but these are the only available references I have.

enter image description here

1
  • 1
    You should try a basic Debug | Compile on your code until all typos are removed. Always. Commented May 30, 2022 at 17:51

1 Answer 1

1

You have a syntax error in the third Line (Long not lon), lon doesn't exist:

Dim CltRow As Long, LastRepRow As Lon, CustCol As Long


Dim CltRow As Long, LastRepRow As Long, CustCol As Long

Also i think you don't want the data type "Long". Instead you want "Row".

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, now I have this error Method 'range' of object '_Worksheet' failed and it shows that it's in this line of code .Range(Sheet2.Cells(1, CustCol).Value).Value = Sheet2.Cells(CltRow, CustCol).Value

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.