Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old May 6th, 2008, 04:09 AM
RiciH83 RiciH83 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 7 RiciH83 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 31 m 36 sec
Reputation Power: 0
Macro to copy a formula

Copy / Pasting an updatable formula !!!


Basically i have a formula in made up of certain cells dependent on what the user inputs. Mainly Date and Months.
From these sells and then combine them ie

EG
=A$1$&""&A$2$&""&A$3$ which i then copy and paste special (formula) into another cell.

result being =VLOOKUP(B2,'I:\Finance & Risk\Procurement\Procurement\Overdue Reports\2008\May\[020508.xls]AP To Action'!$B:$H,6,FALSE)

now being a bit of a noob and not being able to script from scrach im using the record macro i basicaly copy the above.
click a hyperlink to open a workbook and pastespecial (formula) into the new work book.

But when its pasted its like it doesnt auto pick up it being a formula and the only way to get it to work is to highlight the "b2" at the beginning of the formula and then actually click the b2 cell (ie to turn it blue) then it works.

Only problem is that as recording the macro - as soon as i hightlight the b2 bit it saves the entre formula in the macro.

this is what the macro looks like doing the copy and paste action and hilighting the b2

Code:
Range("K6").Select
Selection.Copy
Range("C32").Select
Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
Sheets("Richard").Select
Range("G2").Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-5],'I:\Finance & Risk\Procurement\Procurement\Overdue Reports\2008\May\[020508.xls]Richard'!C2:C8,6,FALSE)"
Range("G2").Select
Selection.AutoFill Destination:=Range("G2:G36"), Type:=xlFillDefault
Range("G2:G36").Select


therefore always picking up from that orignal formula and not the updated one when run (ie the 020508.xls) which would need to change daily.

Basically all i want to do is somehow paste a formula from one workbook to the other and for it to be pick up.

It may be a case i'm not doing something correct earlier or ie creating the formula from multiple cells.

Sorry if it seems a bit long winded, i'm still learning

Reply With Quote
  #2  
Old May 6th, 2008, 10:25 PM
medialint's Avatar
medialint medialint is offline
spirit duplicator
Click here for more information.
 
Join Date: Apr 2004
Location: \\Firecrate\
Posts: 12,325 medialint User rank is General 24th Grade (Above 100000 Reputation Level)medialint User rank is General 24th Grade (Above 100000 Reputation Level)medialint User rank is General 24th Grade (Above 100000 Reputation Level)medialint User rank is General 24th Grade (Above 100000 Reputation Level)medialint User rank is General 24th Grade (Above 100000 Reputation Level)medialint User rank is General 24th Grade (Above 100000 Reputation Level)medialint User rank is General 24th Grade (Above 100000 Reputation Level)medialint User rank is General 24th Grade (Above 100000 Reputation Level)medialint User rank is General 24th Grade (Above 100000 Reputation Level)medialint User rank is General 24th Grade (Above 100000 Reputation Level)medialint User rank is General 24th Grade (Above 100000 Reputation Level)medialint User rank is General 24th Grade (Above 100000 Reputation Level)medialint User rank is General 24th Grade (Above 100000 Reputation Level)medialint User rank is General 24th Grade (Above 100000 Reputation Level)medialint User rank is General 24th Grade (Above 100000 Reputation Level)medialint User rank is General 24th Grade (Above 100000 Reputation Level)  Folding Points: 232775 Folding Title: Super Ultimate Folder - Level 1Folding Points: 232775 Folding Title: Super Ultimate Folder - Level 1Folding Points: 232775 Folding Title: Super Ultimate Folder - Level 1Folding Points: 232775 Folding Title: Super Ultimate Folder - Level 1Folding Points: 232775 Folding Title: Super Ultimate Folder - Level 1Folding Points: 232775 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Months 3 Weeks 12 h 8 m 19 sec
Reputation Power: 2578
Are you sure you don't want to paste the values instead of the formulas?

Try doing that ...

I mean isn't the point to capture a snapshot from the larger picture? I don't think you want to keep references to other workbooks if you don't need them and to make it portable you should have value instead.
__________________
medialint.com

"Energy has the opportunity to change the climate if it's done right." - Sen. John Ensign, R-Nev. (quoted out of context)

Reply With Quote
  #3  
Old May 7th, 2008, 03:07 AM
RiciH83 RiciH83 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 7 RiciH83 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 31 m 36 sec
Reputation Power: 0
Quote:
Originally Posted by medialint
Are you sure you don't want to paste the values instead of the formulas?

Try doing that ...

I mean isn't the point to capture a snapshot from the larger picture? I don't think you want to keep references to other workbooks if you don't need them and to make it portable you should have value instead.


I do need to keep reference to the other workbooks as it pulls through notes that was written on the previous report against invoice numbers.

That is the reason for the vlookup

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Macro to copy a formula


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway