0

VBA novice here

When I run my code I receive the error "Sub or Function not defined". This occurs in one of my subroutines. The first line is highlighted in yellow by the debugger.

Sub Description(Row As Integer, SheetName As String)

With Worksheet(SheetName)

.Cells(Row, 1) = ActiveCell.Offset(0, -3)   
.Cells(Row, 2) = ActiveCell.Offset(0, -2)   
.Cells(Row, 3) = ActiveCell.Offset(0, -1)

End With
End Sub

This subroutine takes in a number and a string. I want to copy specific descriptions into into another worksheet "SheetName". Here is a piece of the code prior to the subroutine call. The value of "x" is declared outside the loops scope.

string_temp = "Sheet2"
ActiveSheet.Cells(i, 5).Select
Call Description(x, string_temp)
x= x + 1

Appreciate the help!

1
  • 5
    It should beWorksheets, not worksheet. Commented Feb 11, 2015 at 23:31

1 Answer 1

1

With Worksheet(SheetName) should be With Worksheets(SheetName)

Also change Row As Integer to Row as Long, Integer is actually marginally slower in VBA as the compiler converts it to a Long for processing.

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

Comments

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.