PDA

View Full Version : Solved: Selection.End Complile Error: Method or Data Member not Found



SherryO
05-03-2007, 07:08 AM
I have a workbook with 13 modules and 13 userforms that up until this morning was working great. What could I have done to it that would cause the "Complile Error: Method or Data Member not Found" to pop up on the End in this line? "Range(Selection, Selection.End(xlToRight)).Select" I'm completely puzzled. What did I do???
Thank you!!

PTs.Worksheets("lookup").Activate
Range("f1:f500").ClearContents
CRE.Worksheets("CurrEAC").Activate
Range("M9").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
PTs.Activate
PTs.Sheets("Lookup").Select
Range("F1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True

johnske
05-03-2007, 07:41 AM
I found this crops up occasionally when using ranges within the range object - it seems the range object prefers to operate on strings, so i routinely use strings now to prevent that i.e. change it to Range(Selection.Address, Selection.End(xlToRight).Address).Select

SherryO
05-03-2007, 07:50 AM
Thank you for the advise, but I'm afraid I don't understand how to use a string for it. Could you give me an example? Also, is there anyway to fix it? Undo whatever it was I did to make it stop working? What did I do to it? It really seems as though it worked at 3PM yesterday and by 9AM today it quit. Rationally I know I did something, but I don't have a clue as to what. I'm feeling like a complete superdork.
Thanks again!

johnske
05-03-2007, 08:02 AM
Replace the line Range(Selection, Selection.End(xlToRight)).Select with Range(Selection.Address, Selection.End(xlToRight).Address).Select. The 'Address' converts it to a string.

What you already have should (theoretically & according to the Help files) work, and i found that it may for quite a long time then - without you doing anything special it will inexplicably fail. That's why I said it seems to 'prefer' operating on strings - call it a bug in visual basic if you like...

SherryO
05-03-2007, 08:07 AM
Ok, now I know you're going to know how ignorant I am, but I still don't understand. What do you set Address to? Am I trying to over-engineer it? Sorry I'm so daft...

johnske
05-03-2007, 08:13 AM
Just replace the line Range(Selection, Selection.End(xlToRight)).Select with Range(Selection.Address, Selection.End(xlToRight).Address).Select

SherryO
05-03-2007, 08:51 AM
It doens't work. I get the same message only this time the Address is highlighted. I thought that's what you meant. Maybe I'm not as daft as I thought...:>

SherryO
05-03-2007, 09:16 AM
It doens't work. I get the same message only this time the Address is highlighted. I thought that's what you meant. Maybe I'm not so much of a twit. So here's what I did...
I copied UserForm by UserForm and Module by Module into a new workbook and tested in between copies for both the .address and just plain .end. It worked perfectly until I copied the attached UserForm into the new workbook. And it works again once it's removed. There's no code in this UserForm. I just started on it. Now is that odd or what? What do you think? As a matter of practice, I'm going to switch everything over to the .address method, but I thought this was just really strange. In any case, thank you so much for the adivse.
Sherry