Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Using split function for a csv file with blank line in between

I used split to convert a csv file into a string array. Everything works
fine until I've a file with empty lines in between and when I run the split
function, my program will give an error "Script out of range" as long as it
hits the blank line. How can I overcome this? Is the empty line causing the
problem ? My script is as below

Open filename For Input As #1
x = 0
m = 1
z = a + b
w = 0
For n = 1 To w
Line Input #1, strline
arrstring = Split(strline, ",")
Worksheets("384-template").Range("B1").Offset(x + z, 0).Value =
arrstring(1){Debug stops here}
Worksheets("384-template").Range("C1").Offset(x + z, 0).Value =
arrstring(2)
Worksheets("384-template").Range("D1").Offset(x + z, 0).Value =
arrstring(0)
x = x + 48
m = m + 1
If m 8 Then
m = 1
x = 0
z = z + 2
End If
'Debug.Print n, x, z, x + z, m
Next n
Close #1


Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Using split function for a csv file with blank line in between

Test your arrstring to see if it is a valid array before attempting to work
with its elements:

arrstring = Split(strline,",")
If LBound(arrstring) <= UBound(arrstring) Then
' do you thing
Else
' empty line read
End If

Note that this method won't work with arrays in general. It will work only
with arrays that are set properly by the Split and a few other functions.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"kfng" wrote in message
...
I used split to convert a csv file into a string array. Everything works
fine until I've a file with empty lines in between and when I run the
split
function, my program will give an error "Script out of range" as long as
it
hits the blank line. How can I overcome this? Is the empty line causing
the
problem ? My script is as below

Open filename For Input As #1
x = 0
m = 1
z = a + b
w = 0
For n = 1 To w
Line Input #1, strline
arrstring = Split(strline, ",")
Worksheets("384-template").Range("B1").Offset(x + z, 0).Value =
arrstring(1){Debug stops here}
Worksheets("384-template").Range("C1").Offset(x + z, 0).Value =
arrstring(2)
Worksheets("384-template").Range("D1").Offset(x + z, 0).Value =
arrstring(0)
x = x + 48
m = m + 1
If m 8 Then
m = 1
x = 0
z = z + 2
End If
'Debug.Print n, x, z, x + z, m
Next n
Close #1


Thanks!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Using split function for a csv file with blank line in between

Thanks a lot! It worked perrfectly fine!

"Chip Pearson" wrote:

Test your arrstring to see if it is a valid array before attempting to work
with its elements:

arrstring = Split(strline,",")
If LBound(arrstring) <= UBound(arrstring) Then
' do you thing
Else
' empty line read
End If

Note that this method won't work with arrays in general. It will work only
with arrays that are set properly by the Split and a few other functions.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"kfng" wrote in message
...
I used split to convert a csv file into a string array. Everything works
fine until I've a file with empty lines in between and when I run the
split
function, my program will give an error "Script out of range" as long as
it
hits the blank line. How can I overcome this? Is the empty line causing
the
problem ? My script is as below

Open filename For Input As #1
x = 0
m = 1
z = a + b
w = 0
For n = 1 To w
Line Input #1, strline
arrstring = Split(strline, ",")
Worksheets("384-template").Range("B1").Offset(x + z, 0).Value =
arrstring(1){Debug stops here}
Worksheets("384-template").Range("C1").Offset(x + z, 0).Value =
arrstring(2)
Worksheets("384-template").Range("D1").Offset(x + z, 0).Value =
arrstring(0)
x = x + 48
m = m + 1
If m 8 Then
m = 1
x = 0
z = z + 2
End If
'Debug.Print n, x, z, x + z, m
Next n
Close #1


Thanks!


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
how to split data where line breaks are the delimiter Jackie Pearce Excel Worksheet Functions 5 April 4th 23 10:55 AM
HOW DO I CHANGE THE COLOR OF THE EXCEL SPLIT LINE JIM123 New Users to Excel 6 April 10th 10 02:54 AM
How do I split the axis scale on a line graph Fish_Biologist Excel Discussion (Misc queries) 2 May 24th 06 05:30 AM
How do you add a blank line automatically after the Subtotal line MVSD Guy Excel Worksheet Functions 0 April 20th 06 01:04 AM
Text File Import leaves a blank row after each line R Kapoor Setting up and Configuration of Excel 0 January 8th 06 02:07 PM


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

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"