+ Reply to Thread
Results 1 to 10 of 10

text to columns not working for me...frustrated

Hybrid View

  1. #1
    Registered User
    Join Date
    09-12-2013
    Location
    NW MN
    MS-Off Ver
    Excel 2010
    Posts
    17

    text to columns not working for me...frustrated

    I have an entire program written that seems to work every once in a while. The one thing that I CANNOT seem to figure out is the range for my text to columns. It is ALWAYS in cell A1, and the destination is ALWAYS A1. Sometimes it will work, and others it won't. I am puzzled. I am guessing something having to do with declaring object, or activeworkbook.worksheets(1).range("A1") needs to happen but I have tried a ton of things and still get a debug error.

    It might be helpful to say I am running this code through outlook, and calling excel. I am unsure if I needed to use "with activeworkbook" and run all my code with that declaration, but I had it then deleted it since I have been getting this error. This is the code for the text to columns. I have a rule set to run this script that saves the attachment, then opens it then needs delimit it. It has run through a few times and when it does it is exactly how I want it. I am guessing this is a simple fix. Thanks in advance!

    Dim rng As range
    Set rng = ws.range("A1")
    
           rng.TextToColumns Destination:=rng, DataType:=xlDelimited, _
            TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
            Semicolon:=False, Comma:=False, Space:=True, Other:=False, 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), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array _
            (20, 1)), TrailingMinusNumbers:=True
    Last edited by JBeaucaire; 10-15-2013 at 11:00 AM. Reason: fixed /CODE tag

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: text to columns not working for me...frustrated

    How is the ws object being set? What if you don't use rng at all?

           ws.range("A1").TextToColumns Destination:=ws.range("A1"), DataType:=xlDelimited, _
            TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
            Semicolon:=False, Comma:=False, Space:=True, Other:=False, 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), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array _
            (20, 1)), TrailingMinusNumbers:=True

  3. #3
    Registered User
    Join Date
    09-12-2013
    Location
    NW MN
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: text to columns not working for me...frustrated

    First, sorry for not including the code tags, totally slipped my mind!

    Here is the full text to columns code. The name of the worksheet I want is named "1", so would activesheet.sheets("1") be the ticket? I am so lost as it works sometimes, but then others it doesn't...realllly frustrating!!!!

    Dim ws As Worksheet
    Set ws = Sheets(1)
    
    Dim rng As range
    Set rng = ws.range("A1")
    
    
    
    
            rng.TextToColumns Destination:=rng, DataType:=xlDelimited, _
            TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
            Semicolon:=False, Comma:=False, Space:=True, Other:=False, 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), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array _
            (20, 1)), TrailingMinusNumbers:=True
    Last edited by pbarry; 10-15-2013 at 05:20 PM. Reason: code tags

  4. #4
    Registered User
    Join Date
    09-12-2013
    Location
    NW MN
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: text to columns not working for me...frustrated

    So, I try this, to no avail. I don't understand how it will work sometimes, but the other times it doesn't. Nothing is changing. Cell "A1" always needs to be delimited, and it is always populated.

    Dim myRange As range
    Set myRange = ActiveSheet.range("A1")

  5. #5
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: text to columns not working for me...frustrated

    I personally don't use Outlook, might need to look into how you are calling Excel. If I were to do it through Access, I couldn't have simply referenced with ActiveSheet.

    I probably would need:
    xlAppObj.ActiveWorkbook.ActiveSheet

    or at least:
    xlWbObj.ActiveSheet

  6. #6
    Registered User
    Join Date
    09-12-2013
    Location
    NW MN
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: text to columns not working for me...frustrated

    I had this in my code
    With xlApp.ActiveWorkbook.ActiveSheet
    How should I use the following code?
    xlAppObj.ActiveWorkbook.ActiveSheet

  7. #7
    Valued Forum Contributor
    Join Date
    11-15-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    538

    Re: text to columns not working for me...frustrated

    Sorry that I don't have a magic bullet, but just a suggestion. See if the functioning/nonfunctioning relates to whether it's the first time the code runs after you open the workbook vs. later. Or if it correlates to right after opening Excel, vs. a second invocation since opening Excel. What I'm going after here is that text-to-column infuriatingly "remembers" how it handled imported data, resulting in inconsistent behavior when you run the same import back-to-back. Maybe this will give you SOME insight into the inconsistency; sorry that's all I can offer.

    For all, besides that being a great example of MS "knowing what is good for you better than you do, so that's how it shall work" and "it's a feature" it prevents you from re-tweaking the delimiters; it just text-to-columns the way it previously did, whether you like it or not. If anyone knows how to prevent that forced "courtesy" of it automatically invoking text-to-column when you repeat it, I've been looking for that for ages. If someone can identify the "rules" for when it does it that would also be useful (e.g., must you restart Excel, etc.).
    Chip, if you can read this, you're STILL making the world a better place with your immeasurably valuable gifts. Every week, you continue to help me (and untold numbers of others) tremendously. Practically no alternative outlets can match your effectiveness, even over the vast number of topics you demystify and empower usage of. You were, and still are, amazing.

  8. #8
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: text to columns not working for me...frustrated

    I was just giving an example, if you have an Excel Application object named xlApp, then just use that, that's fine.

  9. #9
    Registered User
    Join Date
    09-12-2013
    Location
    NW MN
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: text to columns not working for me...frustrated

    hmm....and that doesn't work. I end up getting more errors down that road with method of range and yada yada. The text to columns works fine now though. I really hope I don't have to declare ws as xlApp.activeworkbook.activesheet.range("A1") for everything....Feels liek I am fixing one error and creating another?

  10. #10
    Registered User
    Join Date
    09-12-2013
    Location
    NW MN
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: text to columns not working for me...frustrated

    what I ended up having to do is declare every object by:

    Set xlApp = New Excel.Application
        xlApp.Visible = True
    Set xlWorkbook = xlApp.Workbooks.Open(filename:=strFilename)
    
    Dim wb As Workbook
    Set wb = xlApp.ActiveWorkbook
    Dim ws As Worksheet
    Set ws = xlApp.ActiveWorkbook.ActiveSheet
    So when I used a range, I had to use ws.range("A1") and instead of activeworkbook.saveas it needed to be wb.saveas.

    Maybe this will help others with this issue, or maybe I am the only person out there that needed help because everything needed declaration for some reason?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Text to Columns not working in Excel 2011
    By gcw in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 4
    Last Post: 05-07-2013, 11:23 PM
  2. Text to Columns VBA code not working
    By bjcowen9000 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-20-2013, 11:42 AM
  3. VBA Text to columns not working correctly
    By UberFrank in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-13-2012, 09:59 AM
  4. Reresh All and Text to Columns Macro not working
    By Nick Daniel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-16-2010, 06:55 AM
  5. Number stored as text: Frustrated with Excel-Word Merge
    By Marushel in forum Excel General
    Replies: 2
    Last Post: 03-11-2006, 12:50 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1