Object required error in for each command

nsdcoelho

New Member
Joined
Jul 30, 2014
Messages
10
Hello, I am getting the "object required" error when I try to perform a for each command. Basically, I want, for each string text in a defined array, create a new spreadsheet. However, I got stuck at the for each command. Any help would be appreciated. The code is as follows: Dim rng As Range
Dim cntpies As Range
Dim cntpy As Variant
Dim tabela As String

Worksheets("Lista").Range(Selection, Selection.End(xlDown)).Name = "cntpies"

For Each cntpy In cntpies

tabela = "T." & cntpy
Set WSNew = Worksheets.Add(After:=Sheets(ActiveSheet.Index)).Name = tabela

Next
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I think this line

Worksheets("Lista").Range(Selection, Selection.End(xlDown)).Name = "cntpies"

should be

Set cntpies = Range(Selection, Selection.End(xlDown))
 
Upvote 0
It solved my problem! I was thinking that when defining the name for the range, I was automatically assigning to it the values that are in the range. Thank you all for your help!
 
Upvote 0

Forum statistics

Threads
1,221,525
Messages
6,160,329
Members
451,637
Latest member
hvp2262

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top