1

I've got a worksheet that pulls a lot of data together from the rest of the workbook. My code then runs a 'for each' loop to remove any spaces in the data. The problem is i've got 60 instances of this code to run. From named ranges A1 to A60. My question is can i speed this section of the code up by using arrays? If i'm given pointers with this instance i can apply it to the other instances. I've no experience with arrays hence my need for help.

enter image description here

1
  • 3
    Note that it's best to post your code as a code-block instead of a screenshot. Commented Jun 8, 2021 at 7:10

2 Answers 2

2

I'd look into:

A1.Value = Application.Substitute(A1, " ", "")

Or:

A1.Replace what:=" ", Replacement:="", Lookat:=xlPart

Note that you can add more of the parameters of Range.Replace() to avoid any possible mishaps since this function will save and use settings of previous attempts using this function.

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

Comments

1

Like this:

Dim arr, r as long, v
'...
arr = A1.Value                 'get range values as array
for r = 1 to ubound(arr, 1)
    v = arr(r, 1)
    if len(v) > 0 Then arr(r, 1) = replace(v, " ", "")
next r
A1.Value = arr                 'return values to range

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.