View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz JLGWhiz is offline
external usenet poster
 
Posts: 3,986
Default Combining several workbooks into one file

This will trim all the cells in the used range. If I understand you
correctly, the source file is also an Excel worksheet. The code would need
to be modified to use the source file destination. The filename must be
compatible with the system either showing the file extension or not.
Otherwise you will probably get a subscript out of range message.

Sub celTrim()
Dim c As Range
SourceFile = Workbooks("?.xls") 'Need to sub actual file name
SourceFile.Sheets(1).UsedRange.Select
For Each c In Selection
c = Trim(c.Value)
Next
End Sub

"PJ" wrote:

"Ron de Bruin" wrote:

Hi PJ

You can try the code in the download of this page
http://www.rondebruin.nl/fso.htm


Ron, thank you for your assistance. That worked like a charm. I have two
other "minor" inconveniences as part of this process and was hoping you could
offer a suggestion.

I process each of the original files using a data analytics program and
export my results to Excel. The originals in this case are also Excel files
and each contains a column header with characters that causes problems with
the analytics program so I have to manually rename the column before
importing the files. Second, I combine the data from two columns into one
column before exporting back to Excel and the result needs to be trimmed to
remove the extra spaces.

How can I create a similar macro that will search for the "bad" string and
replace it with a new string before I import my files. And also, is it
possible to modify the existing macro to perform a TRIM on each of the
worksheets, which in each case would be everything in column B.

My hope is to develop a master spreadsheet that can be handed off to a
support person who can click a button to run each macro in the process.
These are the last two issues I need.

Thanks in advance.