0

Merry Christmas all. I'm new to VBA and excel for that matter. I only know how to program in python. I'm trying to create a fairly long macro but am encountering a lot of problems. First, I want to create an array of zeros, which has length equal to the length of the selected cells. I thought this would do it (where the array is called "Split"):

Sub mymacro()

    Dim Split(Selection.Rows.Count) As Integer

End Sub

But I get the "constant value expected" error. How can I do it? Cheers

3
  • See stackoverflow.com/questions/4326678/… Commented Dec 26, 2014 at 16:36
  • What do you mean by the "array of zeros"? Commented Dec 26, 2014 at 17:22
  • By "an array of zeros" I mean an array in which every element is a zero. Commented Dec 26, 2014 at 22:56

1 Answer 1

1

You can use a ReDim statement later in your code.

Sub mymacro()
Dim Split() As Integer
... 
'in the code body
ReDim Split(Selection.Rows.Count) As Integer
End Sub

Two general suggestions:

  1. Don't use "Split" as a variable name. It's a VBA function name.
  2. Don't declare variables as Integer. Use Long instead. In this case, it's actually required, since Integer can't handle the number of rows in a sheet.
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.