Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Open workbook and paste formulas in another

Hello,
I am having trouble pasting formulas from an another workbook into a
main workbook.

I am trying to look for the row with 'Target Renewal'in the first
sheet and then retrieve the formulas within that row. I then want to
take these formulas and copy them into another workbook that has the
same information.


I get an error with this code. I get 'PasteSpecial of Range Class
failed'.

Please help. I am very desperate at this point.

Thanks


Sub PW_OpenFormula()
Dim Wb1 As Workbook
Dim Wb2 As Workbook
Dim Wk1 As Worksheet
Dim Intx As Integer
Dim lngRow As Long
Dim lastrow As Long

ActiveCell.SpecialCells(xlLastCell).Select
lngRow = ActiveCell.Row 'lastcell in spreadsheet
lastrow = 1750

Application.ScreenUpdating = False
Set Wb1 = ActiveWorkbook
Set Wk1 = ActiveSheet
Wk1.Name = "TargetRenewal"
Set Wb2 = Workbooks.Open("C:\target rent\parkwillows\pw_Formula.xls")

For Intx = 1 To lngRow
Cells(Intx, 1).Select
If InStr(1, ActiveCell.Value, " Target Renewal") 0
Then
Range(Cells(Intx, 6), Cells(Intx, 21)).Select
Selection.Copy
End If
Next
Wb2.Close False

With ActiveSheet
For Intx = 1 To lngRow
Cells(Intx, 1).Select
If InStr(1, ActiveCell.Value, " Target Renewal") 0
Then
Range(Cells(Intx, 6), Cells(Intx, 21)).Select
Selection.PasteSpecial Paste:=xlFormulas, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False

End If
Next
End With
Application.ScreenUpdating = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Open workbook and paste formulas in another

You have your .copy inside an If statement. Are you sure that you're copying
something?

Another possible problem. When you close a workbook that's had something
copied, you'll get a prompt asking if the clipboard has been cleared.

Maybe the clipboard has been cleared in your code????

This compiled, but I didn't create a test environment:
Option Explicit
Sub PW_OpenFormula()
Application.ScreenUpdating = False


Dim Wb2 As Workbook
Dim Wk1 As Worksheet
Dim Intx As Long
Dim lngRow As Long
Dim RngToCopy As Range

Set Wk1 = ActiveSheet
Wk1.Name = "TargetRenewal"

Set Wb2 = Workbooks.Open("C:\target rent\parkwillows\pw_Formula.xls")

With ActiveSheet 'wb2.worksheets("sheet1")????
Set RngToCopy = Nothing
'shouldn't be the lastrow in the activesheet
lngRow = .Cells.SpecialCells(xlLastCell).Row
For Intx = 1 To lngRow
If InStr(1, .Cells(Intx, 1).Value, " Target Renewal") 0 Then
Set RngToCopy = .Range(.Cells(Intx, 6), .Cells(Intx, 21))
Exit For 'added
End If
Next Intx
End With

With Wk1
lngRow = .Cells.SpecialCells(xlLastCell).Row
For Intx = 1 To lngRow
If InStr(1, .Cells(Intx, 1).Value, " Target Renewal") 0 Then
If RngToCopy Is Nothing Then
MsgBox "nothing to copy"
Else
RngToCopy.Copy
.Cells(Intx, 6).PasteSpecial Paste:=xlFormulas, _
Operation:=xlNone, SkipBlanks:=False,
Transpose:=False
End If
Exit For '????
End If
Next Intx
End With
Wb2.Close savechanges:=False
Application.ScreenUpdating = True
End Sub

TR wrote:

Hello,
I am having trouble pasting formulas from an another workbook into a
main workbook.

I am trying to look for the row with 'Target Renewal'in the first
sheet and then retrieve the formulas within that row. I then want to
take these formulas and copy them into another workbook that has the
same information.

I get an error with this code. I get 'PasteSpecial of Range Class
failed'.

Please help. I am very desperate at this point.

Thanks

Sub PW_OpenFormula()
Dim Wb1 As Workbook
Dim Wb2 As Workbook
Dim Wk1 As Worksheet
Dim Intx As Integer
Dim lngRow As Long
Dim lastrow As Long

ActiveCell.SpecialCells(xlLastCell).Select
lngRow = ActiveCell.Row 'lastcell in spreadsheet
lastrow = 1750

Application.ScreenUpdating = False
Set Wb1 = ActiveWorkbook
Set Wk1 = ActiveSheet
Wk1.Name = "TargetRenewal"
Set Wb2 = Workbooks.Open("C:\target rent\parkwillows\pw_Formula.xls")

For Intx = 1 To lngRow
Cells(Intx, 1).Select
If InStr(1, ActiveCell.Value, " Target Renewal") 0
Then
Range(Cells(Intx, 6), Cells(Intx, 21)).Select
Selection.Copy
End If
Next
Wb2.Close False

With ActiveSheet
For Intx = 1 To lngRow
Cells(Intx, 1).Select
If InStr(1, ActiveCell.Value, " Target Renewal") 0
Then
Range(Cells(Intx, 6), Cells(Intx, 21)).Select
Selection.PasteSpecial Paste:=xlFormulas, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False

End If
Next
End With
Application.ScreenUpdating = True
End Sub


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
paste formulas between workbooks without workbook link ron Excel Discussion (Misc queries) 3 April 22nd 23 08:11 AM
Slow to Open, Small Workbook <2MB, HTML Paste, VBA procedures Fred Excel Discussion (Misc queries) 0 February 5th 10 09:20 PM
How to copy formulas to a new workbook? Paste Special is different MS-Requestor Excel Worksheet Functions 2 May 10th 06 10:19 PM
Macro to open workbook and copy and paste values in to orig workbo Dena X Excel Worksheet Functions 1 December 15th 05 11:13 PM
Copy worksheet and paste it in New workbook, all data except Formulas Sudarshan Excel Programming 4 May 26th 04 06:51 PM


All times are GMT +1. The time now is 12:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"