Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default INsert Formula via Macro

Hi all

How do I insert a formula in a column via macro, eg I want to insert

=INDEX('C:\[FXAppl.xls]Sheet1'!$C$1:$C$100,MATCH(LEFT(Sheet3!A2,4)&"*",'C :\[FXAppl.xls]Sheet1'!$B$1:$B$100,0)) into column F till the last row with
data.

Thanks

regards, xlsops
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default INsert Formula via Macro

I used column A to determine the last row that should be used. And I placed the
formula in F2:F(lastrow). Your formula looks like you wanted to start in row 2.

Option Explicit
Sub testme()
Dim LastRow As Long
Dim Wks As Worksheet

Set Wks = Worksheets("sheet1")

With Wks
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("F2:F" & LastRow).Formula _
= "=INDEX('C:\[FXAppl.xls]Sheet1'!$C$1:$C$100," _
& "MATCH(LEFT(Sheet3!A2,4)&""*""," _
& "'C:\[FXAppl.xls]Sheet1'!$B$1:$B$100,0))"
End With
End Sub

Notice that the embedded double quotes got doubled ("*" changed to ""*"").

franciz wrote:

Hi all

How do I insert a formula in a column via macro, eg I want to insert

=INDEX('C:\[FXAppl.xls]Sheet1'!$C$1:$C$100,MATCH(LEFT(Sheet3!A2,4)&"*",'C :\[FXAppl.xls]Sheet1'!$B$1:$B$100,0)) into column F till the last row with
data.

Thanks

regards, xlsops


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default INsert Formula via Macro

You might try the below. It is a bare bones code that will do what you are
looking for. I have told the code to start on row 2. If you want it to
start with row one you can edit that below in the Range statement. F2 =
Column F row 2.

Sub Sample()

Dim lngCount As Long


lngCount = ActiveSheet.UsedRange.Rows.Count

Range("F2:F" & lngCount).Formula = "=INDEX('C:\[FXAppl.xls]Sheet1'!$C$1:
$C$100,MATCH(LEFT(Sheet3!A2,4)&""*"",'C:\[FXAppl.xls] Sheet1'!$B$1:$B$100,0))
"
ActiveSheet.Paste



End Sub

franciz wrote:
Hi all

How do I insert a formula in a column via macro, eg I want to insert

=INDEX('C:\[FXAppl.xls]Sheet1'!$C$1:$C$100,MATCH(LEFT(Sheet3!A2,4)&"*",'C :\[FXAppl.xls]Sheet1'!$B$1:$B$100,0)) into column F till the last row with
data.

Thanks

regards, xlsops


--
Message posted via http://www.officekb.com

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
Insert a Formula with a Macro Ed Excel Discussion (Misc queries) 2 October 22nd 06 11:37 PM
Macro to insert formula nobbyknownowt Excel Worksheet Functions 3 June 28th 06 05:16 PM
macro to insert into a formula Todd Excel Worksheet Functions 1 March 8th 06 04:55 PM
HOW DO YOU INSERT A MACRO INTO A FORMULA blopreste3180 Excel Worksheet Functions 6 December 21st 05 08:41 PM
Insert macro into formula Paul Excel Worksheet Functions 1 May 12th 05 08:25 PM


All times are GMT +1. The time now is 02:30 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"