Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Read Multiple Lines


Hi,

If I have a textfile with, for an example, 3 different lines, how can I read that lines and put them in 3 different textboxes per line.

thnx




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
VB.Net Read Multiple Lines In Txt
Hey Guys,

Does anyone have a code on how to read a txt file with multiple lines?

Example of text file

this is my first line
this is the second line
this is the third line
this is the forth line

here is my code but it only displays the last line.

Code:


Imports System
Imports System.IO

Public Class Form1
Private Const FILE_NAME As String = "C: est ext.txt"
Public Sub Main()
If Not File.Exists(FILE_NAME) Then
TextBox1.text = "{0} does not exist." & FILE_NAME
Return
End If
Dim sr As StreamReader = File.OpenText(FILE_NAME)
Dim input As String
input = sr.ReadLine()
While Not input Is Nothing
TextBox1.Text = input
input = sr.ReadLine()
End While
sr.Close()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Main()
End Sub
End Class

How To Locate And Read A Txt File Containing Multiple Lines
hi , i am building a project that contains names of different people .. i have written it in a txt format line by line for example
Code:
david
harry
john
tom
catherine

the number of lines is variable this is my code to read it

Code:
Private Sub Command1_Click()
Dim nFileNum As Integer, sText As String, sNextLine As String, lLineCount As Long

nFileNum = FreeFile
Open "C:UserspannamDesktopNew Text Document.txt" For Input As nFileNum
lLineCount = 1

Do While Not EOF(nFileNum)
Line Input #nFileNum, sNextLine

sNextLine = sNextLine & vbCrLf
sText = sText & sNextLine

Loop
Text1.Text = sText


Close nFileNum

End Sub

but from this code i have to determine the location of the text file in the code itself. what would the code be if the user has to locate it manually ? plus all the text opens up in a single line ..how do i work around it ?
thanking you in advance

Hmm - New Lines Arent Read As New Lines By Vb In A File
Heres the situation
im using urldownloadtofile to download a text file from the internet onto the harddrive. although the textfile on the net has 5 items, each on a single line, when i use that function the file saves as 5 items all on a single line.. and where a new line is supposed to be, i see a "box" in notepad..

needless to say, when i try to load the file into an array using Line Input, all 5 items are on a single array number, instead of one item in each array number..

heres what i mean..

text file online:
a
b
c
d
e

text file when downloaded to hd:
a[]b[]c[]d[]e

the box is interesting, if i copy the entire text from the file on my hd and paste it, they paste with all 5 items on seperate lines..

my question is, how can i load a[]b[]c[]d[]e with one item in each array with VB? line input wont work cause itll store a[]b[]c[]d[]e in one string

Read Lines And Count Lines From Txt File - Thank Ye All
hello again

im back for some more help, so i hope you guys can.

ive had a quick search on the forums for this but cant find anything that helps, so heres my problem:

i have this code:
Code:
Function random2()
Dim lines As Integer
Dim current As String
lines = 0
    Open "C:files.txt" For Append As #1
    Do While Not EOF(1)
        Line Input #1, current
            lines = lines + 1
            MsgBox (current)
    Loop
    Close #1
txtFILE = lines
End Function


but that code doesnt work, it does count the lines at all, i get no msgbox's, no count, no nothing.

any help would be much appreciated.

thanks.


Primary_Slave



----------------------------------------------------------------------------------------
I'm all wrapped up in my binary blanket and I'm coding on late into the night
----------------------------------------------------------------------------------------

Edited by - Primary_Slave on 11/4/2004 9:46:42 AM

What's Best Way To Do Read These Lines?
Each day I am going to first create a text file manually like this:

apples 100
oranges 50
peaches 70
...

There will be about 20 lines. I want to read the items into a string variable and the numbers into a long variable. Each variable will be passed to its own procedure.

What is the best way to do this? Just use regular sequential I/O or do I need random access file? Or should I read each line into an array first and then split them? I don't care if I have to use commas or tabs instead of spaces. For example, it's fine if I have to make the text file look like this:

apples, 100
...
or
apples [tab] 100
...

Thanks.

Read Lines
what i am trying to do is open a file, and on each line will be some text, and for the text on each line, it will go on a row in a ListView. the thing is, i dont know how to find each line in a file or anything like that. I have found no information on this and am hoping someone knows how to do this, thanks

Can I Read Specified Lines In A Txt File??
Hi, i am a very new newbie.
I have a log file like this format:

0
...........(data in the log file, only one line)
0
...........(data in the log file, only one line)
0
...........
...........(data in the log file, two lines)
0
.........
.........
0
..........
0


I want read the data lines enclosed by the "0"s one by one and return it into string.
Any good idea?



Thanks....
Sami

Read Txt File Lines!!!
HI!!
Can anyone please tell me how can i read a specific line in textfile??
like i have 3 lines in text file:
this s first line
second line!
and the third!

How can i read second line???

Thanx!!

How To Read Different Lines In Text?
i want to read line 7 for example and input it's values.. how can i do that?

Read Lines From Textfile
I'll give ya a senario...
on my form, i have:

~10 command buttons
~1 text box
~1 Textfile,,, if this needs to be a .txt or .ANYTHING ill change in a sec (app.path + "settings.ini")

what i want it to do is when i push Command# i want it to display THAT # life of text into the textbox... so for example

if I push Command1 then
take line one from (app.path + "settings.ini")
and display it in Text1.text

if i push button 2, then i want it to display line 2,,, and so fourth, ive been stuck on this for a few days.. looked at multiple good websites, downloaded tutorials, tried to get help from online chats... no luck

please help me, im not really sure where to start, so im totally in the dark

How Do I Read Lines In A Textbox
How do i read lines in a textbox,
I use the open and open a file into the textbox
Text1, when i use :
Text1.Selstart = 0
Text1.SelLength = 200 it copies the whole line plus next line
line number 2, how can i just read the line i need
say i need line 20 this time i need to read the line, i would need the code that can do this job incase i am anotehr window, i had to leave the Text1.SetFocus out, also i had
to leave the SendKeys "{+END}", True because i maybe
in another window to avoid jumping to my program to get a line in a textbox Which is text1 how can i read any line in text1 text1 has 200 lines so i hope you can help me out with
a code that can get the line of text i need to get Line number
55 in a textbox how i go's about doing that.
Thank You Have nice Sunday Evening all

Bye

How To Read Certain Lines In A File And Tell What Is Different
Hello,
I have 2 files that I am going to compare. I was wondering how would I go about to read those files, and tell what is different. Take for instance...that file1.txt has <name>Fred</Fred>
<name>Barney</name>
<name>This</name>
File2.txt has...
<name> Barn</name>
<name> Fred</name>
<name> This</name>

Then I would have file box say file2.txt is different than file1.txt.
Because it has more names than than file1.txt and also file2.txt is missing barney.

Can someone tell me of a website that can help me with this, or can they help me themselves?

Read/Write 2 Lines
Hello all, i'd like to know howto read one line (define it to a variable), and then do the next with the string on the next line. thanks guys ^^

Read More Lines From Textfil
I'm making a program, were i can store my results from school. The results i put into a textfile called: variable.txt.
Now the program have tot read te textfile, and store each line in an variable.
So each line have is own variable.

But now the problem, i created this code for reading and store the variable:

VB Code:
strFile = "C:Documents and SettingsNilsBureaubladcijfersvariable.txt" 'your file with full path file must exist before you read from it    Open strFile For Input As 1 'open text file for reading    Line Input #1, strTemp 'read first string to variable    Close #1    ec1.Text = strTemp


As you see it opens the file variable.txt, read it and puts the data on line 1 into the variable strTemp. After that the variable is shown in an textbox called ec1.

This works fine, but i have more results, and another result is on the second line in variable.txt. I wanna do the same thing with the secondline as with the first line. Someone knows how i should do this?

Read Certain Lines From Txt File
I am reading a txt file for a puzzle game. I use the first line for the Category. The rest of the lines are the answers. I can read line 1 fine to get the Category. I can also read All the Lines for the answers. I need to know how to only read from Line 2 to the EOF for the answers.

Thanks in advance,
Phil

Multiple Lines
I'm createing a very simple forum but am having trouble displaying any message that has been saved that users multiple lines. Below is an example of how it's saved and displayed in the databse but when I retreive and display it on my web page it's just one long string.

"How saved in database"
This
Message
Users
Multiple
Lines.

"How displayed on webpage"
This Message Users Multiple Lines.

I have the message field in my SQL db set to "mediumtext". Is this the correct type of field to use and if so why would it be displayed as one long string instead of how it's saved in the db?

Thanks.

Read From File And Store Lines
Hi there,
This is the code I have so far:
I wish to open this text file and then store each line of the text file in a different variable. Each line consists of a file path.

This is my code so far

It would be really good if anyone could help. Thanks.


Code:
Public Sub actuallybindnow()
Dim thefilenames As String
Open App.Path & "indhelp.txt" For Input As #66
While Not EOF(66)
Input #66, thefilenames
Wend
Close #66
End Sub

How To Read Different Lines Of A Text File?
I'm sure this is an easy enough question to answer but I wasn't able to find any threads about it so my apolgies if it has already been answered.

Basically what I need to do is read different lines of a text file depending on a random number for example on a number of 4 it will read line 4 of the text file. I am aware how to read the first line of a text file with

Open ("C: est.txt") For Input As 1
Line Input #1, strTest
Text1.Text = strTest
Close #1

however I am unaware on how to read any other lines.

Any help is greatly apprecitated thanks in advance

Read First Ten Lines Of A Text File?
I have some code that currently reads the first line of a text file. I want to change this and have it read the first ten lines, is this possible?

Here is the current code (blatantly simple):

'Open File for Reading
Open workfile For Input As #1
'Read in first line of file
Line Input #1, strFilesText
Close #1

Thanks.

Read In LineS Of Text Into An Array
hey guys
i've looked at other posts but can only seem to get this to work for 1 line:

what i want to do.
i have a txt file with data as such
1
2
3
4
5
6
7
8
9
10


i need to read this into an array eg:

dim arrdata(1 to 10)

open **** for input as #1

lineinput #1, data

and from there i'm lost>.........

what is the code i need to:
read line 1, store to arrdata(1)
read line 2, store to arrdata(2)
read line 3, store to arrdata(3)
etc etc etc

is there a way i could do it with a loop
for i=1 to 10 step 1
read line i ???????? store to arrdata(i)
next i

any help appreciated [especially good help cheers

Read First Ten Lines Of Text File?
I have some code that currently reads the first line of a text file. I want to change this and have it read the first ten lines, is this possible?

Here is the current code (blatantly simple):

'Open File for Reading
Open workfile For Input As #1
'Read in first line of file
Line Input #1, strFilesText
Close #1

Thanks.

Read Lines In Files... E.G Line 8 PLEASE Help Me
Hi,
Please could someone give me the code to make it so that my project open a file to read from and read a lien number of my choice...

The code would probaly be in a midule then i would insert the code into a command button     

e.g:

Code:LineNum(8)

This will read from "C: est.txt" and on line 8

If u dont uderstand plz say so...If u do plz help

Thx


------------------------------------------------------------------------------
And when a man gets to heaven,
To saint Paul he'll tell:
1 more soldier reporting sir,
I served My Time in Hell
6 June 1944

2GB DDR400 RAM, 3.4Ghz EM64T P4 Socket 775, 200gb PATA HD 8mb cache, 500GB WD 16mb Cache (Master), 256mb 9950 ATI RADEON AGP ,19" LCD, and a 250W PSU

Running Vs6 Enterprise, running all vs8 products express edition

How To Read A Few Lines From A Text File
HI all - i'm realy stuck

I'm reading a .txt file into a textbox but i'm only interessted in a few lines.

eksample:

DCT4NCK by jozso v0.0a
----------------------
IMEI is '350774103958688'
ASIC Type is 2
Provider is '21601'
Box serial is '32820'

#pw+989202003754006+1#
#pw+253265375104161+2#
#pw+325166543323363+3#
#pw+404257220234456+4#
#pw+058323470625423+5#
#pw+429257443744651+6#



The Above shows whats in my text box.
Now i want to sort out my text so the only thing remaining is:

#pw+989202003754006+1#
#pw+253265375104161+2#
#pw+325166543323363+3#
#pw+404257220234456+4#
#pw+058323470625423+5#
#pw+429257443744651+6#

I tryed "all" But i cant figure out how to do it.

Basicly it would be fine just to read from line 8 -> 13 But how ?

Heres the code i'm using to read the textfile:

Dim FileLength
Open "code.txt" For Input As #1
FileLength = LOF(1)
var1 = Input(FileLength, #1)
calcedcodes.Text = var1
Close #1

I'm realy kind of new to VB so plz take it from the top

Thx in advance



Edited by - Dr.Bizar on 7/26/2003 7:03:33 AM

Read And Count Lines In A Text Box
Often, you may need to know how many lines of text there are in
a multi-line textbox. While Visual Basic makes it easy to determine
how many paragraphs the textbox contains, using code like so:

Private Sub Command1_Click()
Dim myParas As Variant
myParas = Split(Text1, vbNewLine)
MsgBox UBound(myParas) + 1
End Sub

This code, as you can see, only parses out hard carriage returns;
whereas you want to know how many lines of text the control contains.

To accomplish this task, you'll need to resort to the SendMessageAsLong()
API function. This function conforms to the following syntax:

Private Declare Function SendMessageAsLong Lib "user32" _
    Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, ByVal lParam As Long) As Long

To obtain the number of lines, you pass in the EM_GETLINECOUNT
constant in the wMsg parameter. Declare this constant like this:

Const EM_GETLINECOUNT = 186

Finally, to use the function, pass in the handle to the textbox
from which you want to retrieve the line count, as well as the
wMsg we mentioned earlier. Example code might look like so:

Private Sub Command2_Click()
Dim lCount As Long
lCount = SendMessageAsLong(Text1.hWnd, EM_GETLINECOUNT, 0, 0)
MsgBox lCount
End Sub

Read First 6 Lines Of A Text File
I am sure reading from a file question has been asked before. But I am trying to read the first six lines of a file. Can someone give me a small example or any links ?


A VB turned PHP geek

Multiple Lines Of Text
i want to do something like this

Private Sub Command1_Click()
select case lbl1.caption
case = "whatever i have here"
lbl2.caption = "i need to show multiple lines
of text so it looks just like
this when it prints to the lbl2"
end select

End Sub

the problem i am having is that when i put the text in multiple lines like that all the lines except the top one turn red and i get a sytex error. is there a way to do this. the reason i want to do it this way is that i will be doing a lot of copy and paste for my label text and i am using as few labels as i can so im using "select case" to change them.

Getting Data From Multiple Lines
Hi, I have a .txt file with numbers in like the following:
10110
01111
11111
00000
11001

How do I get that data out of the text file? I tried:

Code:
Private Sub cmdRead_Click()
Dim mapdata As Single

Open App.Path & "map.txt" For Input As #1

Input #1, nextline

Text1.Text = Text1.Text & nextline
End Sub

This just puts the first line into the textbox. How do I get all the lines?

BV6 List Box Multiple Lines
Ok,
I'm trying to get some multiple lines working in a list box.
Like you can do in a text box, if the data imputted into the feild is longer that the width of the text box then it would carry onto the next line.

How do you do this on a list box. On a text box there is a option that is 'multiple line' and you just go true.

Also the 2 lines have to be connected as one, e.g. when you select either of the lines it is highlited as one option.

Any ideas.

Multiple Lines Of Text.
I need to know how to get multiple lines of text in lables snd message boxes. I have been using a different lable for each line of text, but there has to be a better way! If any one can help me I'd be greatful.

Multiple Lines In MSFlexGrid Row
hi,

i am populating the flexgrid with data. the column width is fixed and i dont want to change that. what i want is that if text in that column is grater than the column width then it should be displayed in the second line. i mean the rowheight should change. please help me with this..
waiting for replies.

thanx..

Using Replace() With Multiple Lines
I am having a problem with replacing a chunk of strings with absolutely nothing. For example, i want to do the following:

Text1.Text:

Code:
Rawr
Cool
Wee
Wow
Yay
Yay
3218382182183
and replace all instances of

Code:
Rawr
Cool
Wee
Wow
Yay
Yay
with nothing. (vbNullString)

This is what i have:

Code:
Dim f as integer
Dim roffle2 as string
f = freefile
Open "C:Test1.txt" For Input As #f
Do Until EOF(f)
Input #f, roffle2
Text2.Text = Text2.Text + roffle2 + vbCrLf
Text3.Text = Text3.Text + Replace(Text1.Text, Text2.Text, vbNullString) + vbCrLf
Loop
Close #f
However, all that is replaced is the very first line.
Which would be, (referring to the examples) Rawr.
So, in Text3.Text i get a:

Code:
Cool
Wee
Wow
Yay
Yay
3218382182183
Can anyone help me?

If Statement On Multiple Lines
I have an If condition with a lot of 'or' operators and I want to split the expression on multiple lines, but somehow I'm getting a "Compile error: Expected: expression" on the first 'or' on the second line. Can anyone see what's wrong with my statement?

Code:
Private Function CheckResult() As Boolean

If Len(txtM2MIdMenlo.Text) > 0 Or Len(txtM2MIdAustin.Text) > 0 Or Len(txtP21Id70.Text) > 0 & Chr(13) & _
or Len(txtP21Id71.Text) > 0 or Len(txtP21Id72.Text) > 0 or Len(txtP21Id73.Text) > 0 & Chr(13) & _
or Len(txtP21Id74.Text) > 0 or Len(txtP21Id75.Text) > 0 or Len(txtP21Id76.Text) > 0 & Chr(13) & _
or Len(txtP21Id77.Text) > 0 or Len(txtP21Id78.Text) > 0 or Len(txtP21Id79.Text) > 0 & Chr(13) & _ Then
CheckResult = True
Else
CheckResult = False
End If

End Function
Thanks,
poli

Multiple Lines In Clipboard???
Hi all!

I'm using this code to add something to the clipboard:

Clipboard.Clear
Clipboard.SetText "Signature Line 1"

. . . but I want to be able to add more than one line of text to the clipboard, ie:

Signature Line 1
Signature Line 2
Signature Line 3

Is there anyway of building in a line break to the Clipboard.SetText command?

Thanks!

Simon

Multiple Lines From A Txt File
hey ive got a bat file i want to loadin txt format, i can load single lines from it, well the bottom one. can any one help me load it all

heres my code

Quote:




Private Sub cmdLoad_Click()
'Call AboutText
Dim temp As String, Message As Long
'this loads the about txtfile
ChDir App.Path
Open "c:dude.bat" For Input As #1
'While Not EOF(1)
'Line Input #1, temp
Text1.Text = Message '& vbCrLf & temp
'Wend
Close #1
AboutText = Message
End Sub





cheers for the help

Comment Multiple Lines
Is it possible to comment multiple lines without putting ' in front of them all?

Java lets you do this:

/* All
of
this
is commented */

Does VB have an equivalent?

Multiple Text Lines
I want to send many lines of text into one text box. The text that is entered must include earlier entered fields that a user has entered and text i have programed into the box. is there any way in which the text can be displayed on new lines eace time a new field is inserted and each time my text is inserted?

Multiple Lines Of Text
ok how would i display tect on multiple lines useing vb code i already know tht you have to set the property to multiline=true but how would i display the text by useing code and not the property dialog on the side?

Multiple Lines (list)
How do I input multiple lines in the list at one time? Like having a list but something generating mutliple linesmust like this :

Line 1
Line 2
Line 3
......... so on......

Well, later!



Edited by - SourceCode on 3/19/2006 4:18:25 PM

Printing Multiple Lines
I have a program which prints data from a database which works fine except one thing which is if the string Im printing is longer than the page it does not go to the next line and I can not figure out how to check the length of the string and then if need be break it down into smaller strings and print it over multiple lines. A push in the right direction please!!

Read Random Lines From Text File
Hey does anyone know how when i calick a button on my form it will read a random line from a text file that i created and insert it in to a text box?

Thanks For Any Help.

Registry (Save And Read) And Get The # Of Lines In A String!
Since I don't know how to properly use API, can someone please write me a code that has 2 functions (1 for writing strings into the registry and the other for reading from the registry!). Thanks for your help.

Writin Multiple Lines To Files
Hi ive been using :
Open "c:Msg02.dat" For Output As #1
Print #1, msg02
Close #1
to save a message and:
Open "c:Msg02.dat" For Input As #1
Input #1, msg02
Close #1
to open it again, this has worked fine up to now however i need to save a message that is approximately 8 lines long how do i do this
thanks

Text File With Multiple Lines Help.
I got a .txt file, with multiple lines. I don't want to confuse you guys, so i'll give you an easy example of what I'm looking for.

I have a text file with this in it:

Hello this is line 1
and this is 2
this...is line 3

How would I read those lines one by one, or seperate them, becuase when I try to read it with input #filenum, variable , it only returns the first line in the .txt file...
I would appriciate some help :P ty

Multiple Lines In Saved File
When I save my txt files and load them, I'm having issues saving multiple lines for each text box. I have 5 text boxes and they all save/load correctly except for the fact that they each only save 1 line each.

Highlighting Multiple Lines In Word
Hello,

How would I code the macro to highlight everything after the "APN" line until before it hits the "10:00 AM" line?

I am using this code:
Selection.MoveDown Unit:=wdLine, Count:=1
but I don't now where to go from here. help!!

I want to highlight this in word:
--------------------------------------------------
Trustor: Jesse l & Gwendolyn Jones Foreclosing D/T:16117399
other notes go here
--------------------------------------------------


--------------------------------------------------
word document
--------------------------------------------------
5/7/2003 10:00 AM 190 N Market St. SJ REF: 8/22/2002 Pg: 1
*-6 B-8 26950 Arastradero Road APN: 175 42 064
Trustor: Jesse l & Gwendolyn Jones Foreclosing D/T:16117399
other notes go here

5/8/2003 10:00 AM 190 N Market St. SJ REF: 4/17/2003 Pg: 2
12527 Escuela Av Mountain View 94041 APN: 154 02 035
Trustor: Dan L Epstein Foreclosing D/T:15620600
other notes go here

5/8/2003 10:00 AM 190 N Market St. SJ REF: 4/17/2003 Pg: 3
12527 Escuela Av Mountain View 94041 APN: 317 64 089
Trustor: Jack Assp Foreclosing D/T:15620600
other notes go here

--------------------------------------------------

Commnet Box Multiple Lines: &lt;ENTER&gt;
Easy one.

Would like to write commnet box with multiple lines

thing = " something " & " something else"
Cells(1, 1).Comment.Text Text:= thing

where something and something else are two seperate lines in the comment box, i.e. instead of running together.

Help?

dANKE,

mike D

Access - Multiple Lines In A Cell
I have data that is a really long string that is inputed into a database and would like to have multiple lines in an access database. What I am doing is basically a customer name as a column and Items Bought as another column which would be REALLY helpful if each item purchased is on a different line but in the same cell.

Here is part of the code that I am using, but there is ALOT more cases. Ive tryed '& vbcrlf', doesnt work. So all this is, is a long string of items...

Code:
Dim price As Decimal
Dim itemslist As String = ""
Do While ListBox1.Items.Count > 0
Select Case ListBox1.Items.Item(0)
Case "160GB Serial ATA [add $90]"
price += 90
itemslist = itemslist & "160GB Serial ATA [add $90], "
Case "250GB Serial ATA [add $160]"
price += 160
itemslist = itemslist & "250GB Serial ATA [add $160], "
Case "320GB Serial ATA [add $200]"
price += 200
itemslist = itemslist & "320GB Serial ATA [add $200], "

End Select
ListBox1.Items.RemoveAt(0)
Loop
Any help very appreciated!!

Multiple Regression Lines On Same Chart
Below is part of a macro that I recorded to place a chart on the active sheet and add three series of lines on the same chart;


Code:
Charts.Add
ActiveChart.ChartType = xlXYScatterSmooth
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A1")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R6C4:R8C4"
ActiveChart.SeriesCollection(1).Values = "=Sheet1!R6C5:R8C5"
ActiveChart.SeriesCollection(1).Name = "=""Name 1"""
ActiveChart.SeriesCollection(2).XValues = "=Sheet1!R10C4:R12C4"
ActiveChart.SeriesCollection(2).Values = "=Sheet1!R10C5:R12C5"
ActiveChart.SeriesCollection(2).Name = "=""Name 2"""
ActiveChart.SeriesCollection(3).XValues = "=Sheet1!R14C4:R16C4"
ActiveChart.SeriesCollection(3).Values = "=Sheet1!R14C5:R16C5"
ActiveChart.SeriesCollection(3).Name = "=""Name 3"""

I would like, if possible to change this code to automatically add any number of lines to the chart. I tried a For... Next statement where I substituted a variable, e.g. N in the following lines:


Code:
ActiveChart.SeriesCollection(N).XValues = "=Sheet1!R6C4:R8C4"
ActiveChart.SeriesCollection(N).Values = "=Sheet1!R6C5:R8C5"
ActiveChart.SeriesCollection(N).Name = "=""Name 1"""

This did not work since ActiveChart.SeriesCollection(N)... is not an array. I also realize that the Names of each series would have to be different as well and I would have to change the row and column locations through each pass of the loop.

Any way around this dilemma?

Copyright © 2005-08 www.BigResource.com, All rights reserved