R
Rosencrantz
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
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