LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default macro to make named ranges

Hi everyone,

I put this post under a different title, so I decided to try it with a
different subject.

So, I'm making a macro that makes named ranges when the user inputs the
column numbers and then the names of the two ranges. Here's the code as
of now:

Sub update()

Dim columns() As String
Dim length As Integer
Dim X As String
Dim y As String
Dim first As Integer
Dim second As Integer
Dim length2 As Integer
Dim names() As String
Dim name1 As String
Dim name2 As String

Do
output = InputBox("Which column(s)? (up to two and in numeric
value)", "Ranges", "3, 4", , , "c:\Windows\Help\Procedure Help.hlp", 0)
length = Len(output)
Loop Until length < 8

If length 0 Then
columns = Split(output)

X = columns(0)
y = columns(1)

first = Val(X)
second = Val(y)

output2 = InputBox("First name?", "Ranges", "first", , ,
"c:\Windows\Help\Procedure Help.hlp", 0)
name1 = output2

output3 = InputBox("Second name?", "Ranges", "second", , ,
"c:\Windows\Help\Procedure Help.hlp", 0)
name2 = output3

Range(Cells(8, first), Cells(Rows.count, first).End(xlUp)).Name = name1
Range(Cells(8, second), Cells(Rows.count, second).End(xlUp)).Name =
name2

Else
End If

End Sub

It works, but I want to make it more user friendly. My final goal is to
make it work like this type of named range:

=OFFSET(Sheet1!$A$1,1,0,COUNTA($A:$A)-1)

So that it will automatically be updated when new data is put in the
columns, along with any graphs and equations that use the named range.
At the moment, I have to go into the graphs and manually change the
code from this:

=SERIES(,grnd_results_d1_text_file.txt!$G$8:$G$56, grnd_results_d1_text_file.txt!$H$8:$H$56,1)

to this:

=SERIES(,grnd_results_d1_text_file.txt!FIRST,grnd_ results_d1_text_file.txt!SECOND,1)

I want to avoid this typing and code the macro in such a way that the
graphs will automatically use the named range of the columns called in
the graph.

Also, when new data is added, at the moment I have to rerun the macro.
This could lead to typing error in the names fo the ranges so the
graphs may not update.

Any thoughts on these? I'm new to VBA so I may be missing something
obvious, so any help is greatly appreciated!

Thanks in advance!
~M

 
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
Referring to named ranges in a macro Pontificateur Excel Programming 5 September 16th 05 06:23 PM
How do I get a macro to ask for a 'range' to go to with a choice of Named ranges? neuf Excel Programming 1 June 4th 05 05:33 PM
Macro (Print) - Calling Named Ranges KGlennC Excel Discussion (Misc queries) 1 March 19th 05 09:20 PM
Macro eliminating named ranges JonR Excel Programming 1 January 18th 05 02:03 AM
Named Ranges - Macro Problems Karl Burrows Excel Programming 2 April 4th 04 06:03 PM


All times are GMT +1. The time now is 10:52 PM.

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

About Us

"It's about Microsoft Excel"