Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default I want to loop this macro

This macro allows me to name cells very easily:

Sub NameCells()

Dim w As String
Dim cell As Range

w = Cells(ActiveCell.Row, 1) & "_" & Cells(2, ActiveCell.Column)
w = Replace(w, "& ", "")
' several other replacements that I omitted for brevity's
sake
ThisWorkbook.Names.Add Name:=w, _
RefersTo:=ActiveCell, _
Visible:=True

End Sub

The trouble is that I have to click the macro in each cell that I want
to name. I am using this on financial statements, and I have to do it
about 200 times every time I import a new set. Is there any way to
loop this so that I can select a range of cells, and it will
automatically name all of them based on the above criteria?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default I want to loop this macro

Give this a try. I have replaced ActiveCell with a variable that is
passed as a parameter from a calling function:

Sub NameSelected()
Dim c As Range
For Each c In Selection
NameCells c
Next
End Sub


Sub NameCells(r As Range)
Dim w As String
Dim cell As Range

w = Cells(r.Row, 1) & "_" & Cells(2, r.Column)
w = Replace(w, "& ", "")
ThisWorkbook.Names.Add Name:=w, _
RefersTo:=r, _
Visible:=True
End Sub



On Jul 30, 2:48*pm, DoooWhat wrote:
This macro allows me to name cells very easily:

Sub NameCells()

Dim w As String
Dim cell As Range

* * w = Cells(ActiveCell.Row, 1) & "_" & Cells(2, ActiveCell.Column)
* * w = Replace(w, "& ", "")
* * * * * *' several other replacements that I omitted for brevity's
sake
* * ThisWorkbook.Names.Add Name:=w, _
* * * * RefersTo:=ActiveCell, _
* * * * Visible:=True

End Sub

The trouble is that I have to click the macro in each cell that I want
to name. *I am using this on financial statements, and I have to do it
about 200 times every time I import a new set. *Is there any way to
loop this so that I can select a range of cells, and it will
automatically name all of them based on the above criteria?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default I want to loop this macro

Thank you so much! That worked to perfection.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro Loop stan Excel Discussion (Misc queries) 1 October 22nd 09 04:38 PM
Loop Macro Roger Excel Programming 1 February 26th 08 11:57 PM
Help with using a Macro Loop Mark Costello[_2_] Excel Discussion (Misc queries) 5 October 19th 07 02:01 PM
Do until loop with use of another macro in loop The Excelerator Excel Programming 9 February 28th 07 02:28 AM
VBA Macro Loop Neutron1871 Excel Programming 1 November 4th 04 09:22 AM


All times are GMT +1. The time now is 04:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"