Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
KCK KCK is offline
external usenet poster
 
Posts: 14
Default Formula in macro causes macro to fail

Hi, I am pretty new to writing macro's and need some help. I am writing a
macro to insert some formulas into cells. It inserts my first formula fine
but when it gets to the second formula it fails and ask if I want to debug.
The second formula is doing a vlookup on a second file using an IF(ISERROR)
functions to determine which file it finds the matched data in. the formula
works great outside the macro. Any help would be greatly appreciated.
Here is a small portion of the macro.

Thanks,
Kerry

Sub Macro3()
'
' Macro3 Macro
'
Range("Q1").Select
ActiveCell.Offset(2, -1).Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "."
ActiveCell.Offset(-1, 0).Range("A1").Select
Selection.End(xlUp).Select

' This formula works fine ------------------------------------
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = _

"=TRIM(CLEAN(SUBSTITUTE(LEFT(TRIM(RC[-14]),LEN(TRIM(RC[-14]))-OR(RIGHT(TRIM(RC[-14]))={""?"",""!"","".""})),CHAR(160),"" "")))"

' The macro stops on this formula---------------------------
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = _
"=IF(ISERROR(VLOOKUP(RC[-2],'[KK-Chargeback Sales Order Freight
Details.xls]Sales Pays'!$S:$T,2,FALSE)),VLOOKUP(RC[-2],'[KK-Chargeback
Inbound Cost at PO Receipt.xls]By
Receiver'!$S:$T,2,FALSE),VLOOKUP(RC[-2],'[KK-Chargeback Sales Order Freight
Details.xls]Sales Pays'!$S:$T,2,FALSE))"
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "s"
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Formula in macro causes macro to fail

KCK,

You are mixing your cell reference modes: $S$T is not R1C1. Record a macro, select the cell with
the formula, press F2, then press enter, and you will see the difference in the code.

HTH,
Bernie
MS Excel MVP


"KCK" wrote in message
...
Hi, I am pretty new to writing macro's and need some help. I am writing a
macro to insert some formulas into cells. It inserts my first formula fine
but when it gets to the second formula it fails and ask if I want to debug.
The second formula is doing a vlookup on a second file using an IF(ISERROR)
functions to determine which file it finds the matched data in. the formula
works great outside the macro. Any help would be greatly appreciated.
Here is a small portion of the macro.

Thanks,
Kerry

Sub Macro3()
'
' Macro3 Macro
'
Range("Q1").Select
ActiveCell.Offset(2, -1).Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "."
ActiveCell.Offset(-1, 0).Range("A1").Select
Selection.End(xlUp).Select

' This formula works fine ------------------------------------
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = _

"=TRIM(CLEAN(SUBSTITUTE(LEFT(TRIM(RC[-14]),LEN(TRIM(RC[-14]))-OR(RIGHT(TRIM(RC[-14]))={""?"",""!"","".""})),CHAR(160),""
"")))"

' The macro stops on this formula---------------------------
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = _
"=IF(ISERROR(VLOOKUP(RC[-2],'[KK-Chargeback Sales Order Freight
Details.xls]Sales Pays'!$S:$T,2,FALSE)),VLOOKUP(RC[-2],'[KK-Chargeback
Inbound Cost at PO Receipt.xls]By
Receiver'!$S:$T,2,FALSE),VLOOKUP(RC[-2],'[KK-Chargeback Sales Order Freight
Details.xls]Sales Pays'!$S:$T,2,FALSE))"
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "s"
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
KCK KCK is offline
external usenet poster
 
Posts: 14
Default Formula in macro causes macro to fail

Worked like a charm! Thanks !

"Bernie Deitrick" wrote:

KCK,

You are mixing your cell reference modes: $S$T is not R1C1. Record a macro, select the cell with
the formula, press F2, then press enter, and you will see the difference in the code.

HTH,
Bernie
MS Excel MVP


"KCK" wrote in message
...
Hi, I am pretty new to writing macro's and need some help. I am writing a
macro to insert some formulas into cells. It inserts my first formula fine
but when it gets to the second formula it fails and ask if I want to debug.
The second formula is doing a vlookup on a second file using an IF(ISERROR)
functions to determine which file it finds the matched data in. the formula
works great outside the macro. Any help would be greatly appreciated.
Here is a small portion of the macro.

Thanks,
Kerry

Sub Macro3()
'
' Macro3 Macro
'
Range("Q1").Select
ActiveCell.Offset(2, -1).Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "."
ActiveCell.Offset(-1, 0).Range("A1").Select
Selection.End(xlUp).Select

' This formula works fine ------------------------------------
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = _

"=TRIM(CLEAN(SUBSTITUTE(LEFT(TRIM(RC[-14]),LEN(TRIM(RC[-14]))-OR(RIGHT(TRIM(RC[-14]))={""?"",""!"","".""})),CHAR(160),""
"")))"

' The macro stops on this formula---------------------------
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = _
"=IF(ISERROR(VLOOKUP(RC[-2],'[KK-Chargeback Sales Order Freight
Details.xls]Sales Pays'!$S:$T,2,FALSE)),VLOOKUP(RC[-2],'[KK-Chargeback
Inbound Cost at PO Receipt.xls]By
Receiver'!$S:$T,2,FALSE),VLOOKUP(RC[-2],'[KK-Chargeback Sales Order Freight
Details.xls]Sales Pays'!$S:$T,2,FALSE))"
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "s"
End Sub




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
Formula help - Sum results Pass or Fail Nadine Excel Worksheet Functions 9 August 6th 13 10:20 AM
Formula & functions intermittently fail to calculate LBarnes Excel Worksheet Functions 2 October 20th 05 06:32 PM
Excel 2000 = upgraded to 2003 and macro to change font color fail Donna Excel Programming 4 October 4th 05 10:25 PM
A macro that copies and pastes autofiltered cells will fail. Mafunzalo Excel Programming 2 July 13th 05 05:43 PM
add-in macro strange errors--method sheets of object workbook fail DavidH[_2_] Excel Programming 3 November 4th 04 05:49 AM


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