Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #33  
Old 06-23-2014, 06:48 PM
BobBridges's Avatar
BobBridges BobBridges is offline NEWB to Macros - formatting exports Windows 7 64bit NEWB to Macros - formatting exports Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

Oh, I don't want you to give up on TextToColumns; I just didn't want to talk about it much until we'd covered some more basic things. Maybe I still don't; I'm thinking.

But you're pretty insistent, even to the extent of deleting your previous posts so I couldn't be distracted by them. You may be biting off more than you can chew just yet, but I gotta respect your determination, so let's give it a try. Start here: Do you have those links I gave you? One of them, this one, is for the objects, properties, methods and events (and other stuff) available to VBA in the Excel application. That's where you'll find official documentation of TextToColumns.

Now, the problem with this link is that it starts with just a list of objects: Worksheets, Error, Hyperlinks, Comments and tons of stuff that I never heard of. None of them are named "TextToColumns". If you ask that page to do a search for "TextToColumns", you'll find—at least I find—lots of articles that mention TextToColumns, but they vary in quality and sometimes I can spend all day trying to understand an article only to realize that it's for Visual Basic Studio or written for C# or something. Very frustrating. Nevertheless, a search is sometimes your only recourse.

But I won't make you search for the relevant article. (I'll just make you read it, once we find it.) I happen to know that TextToColumns is a "method" of the Range object. So start here: Go to that link, and scroll down until you find the Range object mentioned. Click on that. Don't click on the Ranges object, plural; we want the singular.

(Don't worry about which list of objects to use; the left and right are both the same. At least, I've never noticed any difference.)

Once you're there you'll see a choice of four links: "Range Object (Excel)", "Range Members (Excel)", "Properties" and "Methods". You should at least read the "Range Object (Excel)" article; it's short and gives background. But for TextToColumns I recommend you click on "Range Members (Excel)" and then look through the resulting list of Methods in the first section. They're alphabetically arranged, so you won't have any difficulty finding TextToColumns.

The resulting page shows the arguments you use to control the TextToColumns method and a very little about what it does. But it's the right place to start to understand how to do TextToColumns in VBA.

I'm not abandoning you here; I'll still answer questions, either about the documentation itself or about your attempts to make TextToColumns work in your program. But make as much sense as you can of that article, to start with. You seem to be pretty self-reliant, so I'm sure it'll help you some. Then ask some more.

...And as for the questions you already asked:
Quote:
...is "TextToColumns" a FUNCTION?
The short answer is "no, it's a method". But maybe that's not very helpful at this early stage; I didn't know what "method" meant, when I was first starting out.

I gather you know the difference between a subroutine and a function. But both of them are alike in one way: They're available to use anywhere; you can give them any arguments and they'll work as designed. A method, on the other hand, isn't a general routine that you can call like this:
Code:
x = MyFunction(Cells("E2"), 3.14159)
Instead it's a subroutine or function that works only for one particular object—in fact the subroutine exists only within that one object, it was defined as part of that object.

To answer another part of your question, no; the TextToColumns method is more like a subroutine than a function, because it doesn't (so far as I know) return a result, it just performs the action.

As for your code:
Code:
Selection.TextToColumns
   Destination = Range("E2")
   DataType = xlFixedWidth
   FieldInfo = Array(Array(0, 9), Array(3, 3))
...there are probably more corrections to make, but it looks to me like you're on the right track but you need a syntax change. Assuming all these arguments are about right—I'm not assuming that, we'll have to look at them in detail and I haven't yet, but assuming—then the statement would look more like this:
Code:
Selection.TextToColumns Destination:=Range("E2"), DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 9), Array(3, 3))
That's a long statement; it's better to use the continuation character like this:
Code:
Selection.TextToColumns Destination:=Range("E2"), DataType:=xlFixedWidth, _
  FieldInfo:=Array(Array(0, 9), Array(3, 3))
I'm not saying this is perfect, just that the syntax is more what you need. This looks like a function or subroutine, in that you call TextToColumns and provide the arguments—named arguments, in this case, rather than positional. That's why you use ":=" instead of just "=".
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting contents after Tab of continuous lines or formatting specific area of word pawii Word 1 05-12-2014 05:24 AM
macros stebrownsword Word VBA 0 08-28-2013 01:16 AM
NEWB to Macros - formatting exports How to do Formatting Using Macros anju16saini Word VBA 1 03-11-2013 04:15 AM
NEWB to Macros - formatting exports Formatting with macros WaltR Word VBA 8 05-15-2012 06:28 PM
Macros nore Outlook 0 06-01-2011 04:39 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:04 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft