1

I need to create a given number of sheets, depending on the amount of names in a List. The sheets need to have the same name as the string value in every cell inside the list/array. So far my code, which is not working:

Private Sub loopfilter()

Dim VersandRange As Range
Dim rng As Range
Dim Name As String

Set VersandRange = Range("J2", Cells(Rows.Count, "j").End(xlUp))

    For Each rng In VersandRange

            rng.Value = Name
            Worksheets.Add
            ActiveSheet.Name = Name
    Next
end sub

Thanks!

2
  • 3
    One line is reversed Name=rng.Value Commented Mar 17, 2017 at 11:04
  • 1
    or just Worksheets.Add.Name = rng.Value Commented Mar 17, 2017 at 11:44

1 Answer 1

2

Would this not work?

For Each rng In VersandRange
    Worksheets.Add
    ActiveSheet.Name = rng.Value
Next
Sign up to request clarification or add additional context in comments.

4 Comments

@Urumita sheet names are limited to 31 characters and can't contain any of those 7 characters \/*[]:? accountingweb.com/technology/excel/…
Thank you slai, but it is not the case. Im using none of those characters and the maximum =Long I have is 22
You've only swapped out the For.. Next part of your code with mine, yes?
What is the rest of the error generated under code 1004?

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.