Text to Column (1 Viewer)

jalopez453

Registered User.
Local time
Yesterday, 18:34
Joined
Oct 11, 2016
Messages
18
Hi everyone, I am having trouble formatting my csv file to text to column.
Below is my code and I am getting an error for the Destination:=Range("A1") stating,"sub or function not defined".


Code:
With xlApp
    'delete row 1 and 2
    .Rows("1:2").select
    .Selection.Delete Shift:=xlUp
    .Range("A1").select
    
    .Range("A:A").select
    .Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
        :="|", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, _
        1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12 _
        , 1), Array(13, 1), Array(14, 1), Array(15, 1)), TrailingMinusNumbers:=True
    .Range("A1").select
End With
 

MarkK

bit cruncher
Local time
Yesterday, 18:34
Joined
Mar 17, 2004
Messages
8,180
Needs to be...
Code:
.Range("A1")
...because it is a member of your With block variable, xlApp.
Mark
 

jalopez453

Registered User.
Local time
Yesterday, 18:34
Joined
Oct 11, 2016
Messages
18
Hi Mark, I tried it, didn't get the error this time, but nothing happens in the file and the text is not formatted to column after it goes through. Would you happen to know why nothing is happening?
 

MarkK

bit cruncher
Local time
Yesterday, 18:34
Joined
Mar 17, 2004
Messages
8,180
No, I don't know why, but it looks like you are specifying lots of optional parameters that are the same as the defaults. Maybe try the command with a simpler list. Tab, SemiColon, Comma, Space all default to false, so omit them. Also it looks like the FieldInfo parameter--as you've specified it--simply converts everything to General Text, but that too is an optional parameter. Try the command without specifying that parameter.

A general rule for me in developing/debugging is try the simplest route first. Then, if it fails, you have the simplest form of the problem to debug. If you run the simplest route successfully, then start adding variables/distinctions/refinements one by one, testing as you go.

hth
Mark
 

Users who are viewing this thread

Top Bottom