Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Excel and Text Files - Extracting

All

I have an Excel sheet that I need to be able to export in a particular way -
This will be extracted to a text file (csv).

What I need to be able to do is apply the following criteria to the data before
it is extracted. If any data within column C is over 20 characters long only
export the first 20 characters. Also, if the data is less than 20 - for
example 7 apply 13 spaces to the data to ensure that 20 characters worth are
extracted in the csv file.

Appreciate any help you can offer. thanks - Al ( )
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default Excel and Text Files - Extracting

Al

This is my reply to a similar problem where all the fields needed to be a
fixed length. Perhaps you can adapt this?

Sub WriteFixedFile()
Dim LastRow As Long
Dim i As Long
Dim sRecord As String
LastRow = Range("A65536").End(xlUp).Row
Open "c:\TESTFILE" For Output As #1 ' Open file for output.
For i = 1 To LastRow
sRecord = Range("A" & i).Value & Space(15 - Len(Range("A" & i)))
sRecord = sRecord & Range("B" & i).Value & Space(5 - Len(Range("B" &
i)))
sRecord = sRecord & Range("C" & i).Value & Space(10 - Len(Range("C" &
i)))
sRecord = sRecord & Range("D" & i).Value & Space(15 - Len(Range("D" &
i)))
'Write #1, sRecord ' data surrounded by quotes
Print #1, sRecord ' no quotes
Next 'i
Close #1
End Sub

You might need to do some calculation as you want to truncate the length.
The assumption with the above code was that the data would always be less in
length than the maximum size of the fields.

Regards

Trevor



"MrAlMackay" wrote in message
...
All

I have an Excel sheet that I need to be able to export in a particular

way -
This will be extracted to a text file (csv).

What I need to be able to do is apply the following criteria to the data

before
it is extracted. If any data within column C is over 20 characters long

only
export the first 20 characters. Also, if the data is less than 20 - for
example 7 apply 13 spaces to the data to ensure that 20 characters worth

are
extracted in the csv file.

Appreciate any help you can offer. thanks - Al ( )



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
Excel (xls) files spontaneously converting to text files Be-jamin Excel Discussion (Misc queries) 0 November 18th 08 05:31 PM
Extracting data from large text files for beginner [email protected] Excel Worksheet Functions 1 November 12th 08 09:23 AM
Extracting excel worksheet data to separate files [email protected] Excel Discussion (Misc queries) 4 July 23rd 07 08:43 PM
Extracting data from multiple excel files. helphelp Excel Discussion (Misc queries) 2 May 10th 06 09:45 PM
extracting text from within a cell - 'text to rows@ equivalent of 'text to columns' Dan E[_2_] Excel Programming 4 July 30th 03 06:43 PM


All times are GMT +1. The time now is 09:07 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"