Trying to define the same range (A:WWW)
for each worksheet that is on a list in Sheets("B").Range(C10:C42)
but below shown code is not working.
Sorry for not explaining the macro's objective well enough. Please let me try again here: The objective is to name 20 ranges from 20 worksheets. Example: There are 20 sheets, named apple, orange, grape, etc. This name list is in sheet "Background" in C1:C20, let's say. So... In Apple sheet: Name columns A:WWW as "Hist_Apple" In Orange sheet: Name columns A:WWW as "Hist_Orange" In Grape sheet: Name columns A:WWW as "Hist_Grape" Etc... for 20 times. Thank you for the quick response!!
Sub Define_Range()
Dim ws As Worksheet
Dim rng As Range
Dim foundws As String
For Each ws In ThisWorkbook.Worksheets
Set foundws = Sheets("B").Range("C10:C42").Find(ws.Name, LookAt:=xlWhole)
If foundws Is Nothing Then
Sheets(foundws).Select
With ActiveWindow
Set rng = foundws.Range("$A:$WWW")
ActiveWorkbook.Names.Add Name:="Hist_" & foundws.Name, RefersTo:=rng
End With
End If
Next ws
End Sub