Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Paste function error in my macro????? 2

Status
Not open for further replies.

julius1

Technical User
Oct 31, 2002
142
US
I have 2 columns, A is the raw data and B is the additional character I need to merge it with into column C.
A- E.123456
B- .C
C- E.123456.C

Problem is when the macro gets to this point I get a Run time error 1004
Paste method of Worksheet class class failed

this is the code area that comes up for the debugging:

Workbooks.OpenText Filename:= _
"C:\Documents and Settings\jwg052057\Desktop\Book5.txt", Origin:=xlWindows, _
StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 9), Array(4, _
1), Array(12, 9))
Range("B2").Select
ActiveCell.FormulaR1C1 = ".C"
Range("C2").Select
ActiveSheet.Paste (This is the line that comes up in yellow)
Range("B2:C2").Select
Selection.AutoFill Destination:=Range("B2:C3528"), Type:=xlFillDefault
Range("B2:C3528").Select
Columns("C:C").Select
Selection.Copy

This beast is almost done, with the exception of this. Any one have any ideas? Thanks!

julius.gazdag@centurytel.com
Im a Telco guy, I can get you where you want to go, but I can't guarantee it will work when you get there!
 
Try ActiveCell.Paste

I am assuming you are getting that error and it says something like the areas are not of equal size.

dyarwood
 
No, all it states is the paste error. The formula in column C is suppose to be A2&B2 to merge them, but it never does happen.

julius.gazdag@centurytel.com
Im a Telco guy, I can get you where you want to go, but I can't guarantee it will work when you get there!
 
How about the following

a = Cells(i,1).Value
b = Cells(i,2).Value
c = a & b

Or a formula like

Range("C2").FormulaR1C1 = "=A2 & B2"
Something like that will mean that you don't need to copy and paste.

dyarwood
 
Have you tried the Concatenate function?
-->Range("C2").FormulaR1C1="=Concatenate(A2, B2)
;-)

Andreas Galambos
EDP / Technical Support Specialist
(andreas.galambos@bowneglobal.de)
HP:
 
Ok, I am really confused. The macro works now and pastes it to the main spreadsheet. Thanks! for that.
I am wondering can I run a formula in the main sheet?
Can I paste it or do I have to type it in for the cell?
Here is my vlookup
=VLOOKUP(A2,NOV26DATES03.xls!$A$2:$B$8663,2,FALSE)
I have paste that into the cell while recording my macro.
Now when I get to the point of it having to do the vlookup and obtain the value, it gives me the paste error again.

The last one from above, I entered the formula manually and it seemed to work, but i am not sure if this vlookup will be recorded correctly.

julius.gazdag@centurytel.com
Im a Telco guy, I can get you where you want to go, but I can't guarantee it will work when you get there!
 
Do something like the following

Range("A2").FormulaR1C1 = "=VLOOKUP(A2,NOV26DATES03.xls!$A$2:$B$8663,2,FALSE)"

that will put that formula into cell A2 from the code.

dyarwood
 
Ok, I re ran the process, and it does record the formula. All worked out great Thanks guys!!

julius.gazdag@centurytel.com
Im a Telco guy, I can get you where you want to go, but I can't guarantee it will work when you get there!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top