View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default "Text to Columns" for many columns in Excel 2003

I don't usually read the subjects. I figure that anyone would give the
particulars in the body of the message. But I guess I'm wrong.

The next problem you're going to have when you try to parse each column is that
as soon as you parse on column, I'm betting that the adjacent columns (to the
right) get overwritten by the Data|Text to columns.

How are you going to approach this?

Do you know the maximum number of fields that will be created? Does your data
have that many columns available in those adjacent columns or will you have to
insert columns. Or do you skip way over to AH1--I can't tell where your
selection is when the macro starts.

Option Explicit
Sub Convert2Text2()

Dim iCol As Long
With ActiveSheet
'assumes that you'll skip 6 columns between data|text to columns
For iCol = .Range("ah1").Column To .Range("Fa1").Column Step 6
With .Range(.Cells(1, iCol), .Cells(255, iCol))
If Application.CountA(.Cells) 0 Then
.TextToColumns Destination:=.Cells(1), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, _
Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, _
FieldInfo:=Array(1, 2), TrailingMinusNumbers:=True
End If
End With
Next iCol
End With
End Sub

I expected no more than 6 fields from any column to be overwritten. If your
data isn't set up this way, then this won't work.

NickName wrote:

If you want to see some code, then I'd suggest you record a macro when you do
one column the way you want.

Man, you're almost as absent-minded as me sometimes, the title says
Excel 2003.

OK, about the macro, I have a question, the recorded macro looks like
this
Sub Convert2Text()
'
' Convert2Text Macro
'
Selection.TextToColumns Destination:=Range("AH1"),
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False,
FieldInfo _
:=Array(1, 2), TrailingMinusNumbers:=True
End Sub

Now, what I wanted to do is, to expand the Range, so, change the above
to something like

Sub Convert2Text()
'
' Convert2Text Macro
'
Selection.TextToColumns Destination:=Range("AI1..FA255"),
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False,
FieldInfo _
:=Array(1, 2), TrailingMinusNumbers:=True
End Sub

But VB does not like it, could I use a range like that? Or syntax
error? Tks.


NickName wrote:

Dave Peterson wrote:
If you have 300 columns of data, you're not using xl2003 or below.

But data|text to columns only works on a single column at a time.
Yes, I know that.


Maybe you could have a macro that did what you needed. So you could select the
range to fix and then invoke that macro.
Please refer to my OP. I've never used Excel macro before, not an
extensive Excel user. Thks.




NickName wrote:

Dave Peterson wrote:
Select your range (but it has to be a single column) of 200 cells.

Then click on Data|Text to columns.

And follow the wizard.

No. You did not answer the question. The data sets to be formatted as
"Text" overlaps many rows and many columns. No problem of doing it by
hand (manually), however, that would be silly if you have, say, 300
columns and 500 rows to do, formatting the whole range using datatype
of "Text" does not work neither, very weird.

NickName wrote:

Bob Umlas wrote:
Text to Columns is something applied to ROWS, not Columns. It distributes
data in several rows (or one) across columns, so something like
1,2,3,4,5,6 would get distributed to columns A:F if the comma were the
delimiter, for example.
Your question doesn't really apply here, unless I'm misunderstanding the
question.

Then what's an efficient way to apply the "Text to Columns" feature to
many
many (say, 200) rows in Excel 2003? btw, the naming of this feature is
misleading, it would be more accurate if named something like "Convert
to Text" regardless of Column or Row but forget about this.

Also, copying a cell's format and past special (for the format to a
range of cells) would not work, weird.


"NickName" wrote in message
oups.com...
Hi,

What is an efficient way to apply the "Text to Columns" feature to many
many (say, 200) columns in Excel 2003? A macro? If so, can I see some
sample code for that?

TIA.


--

Dave Peterson

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson