Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA problem, works fine as formula but not in VBA

Hi,

I have a formula that works fine in my spreadsheet but when I try t
record it as a macro it no longer works.

Here's the formula that works:

=IF(IF(H2="40DV",INDEX('THC Table'!E:E,MATCH(C2,'TH
Table'!B:B,0)),IF(H2="40HC",INDEX('THC Table'!H:H,MATCH(C2,'TH
Table'!B:B,0)),IF(H2="20DV",INDEX('THC Table'!D:D,MATCH(C2,'TH
Table'!B:B,0)))))-T2=0,"ok","ERROR")


And here's the VBA code I get when I record the formula as a macro
which doesn't work (seems like the first "IF" statement doesn't ge
recorded):

Range("AC2").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-21]=""40DV"",INDEX('TH
Table'!C[-24],MATCH(RC[-26],'TH
Table'!C[-27],0)),IF(RC[-21]=""40HC"",INDEX('TH
Table'!C[-21],MATCH(RC[-26],'TH
Table'!C[-27],0)),IF(RC[-21]=""20DV"",INDEX('TH
Table'!C[-25],MATCH(RC[-26],'THC Table'!C[-27],0)))))?"
Range("AC2").Select


Please help, thanks.:confused

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default VBA problem, works fine as formula but not in VBA

Hi
the recoreded code look o.k (besides the trailing '?')

--
Regards
Frank Kabel
Frankfurt, Germany


Hi,

I have a formula that works fine in my spreadsheet but when I try to
record it as a macro it no longer works.

Here's the formula that works:

=IF(IF(H2="40DV",INDEX('THC Table'!E:E,MATCH(C2,'THC
Table'!B:B,0)),IF(H2="40HC",INDEX('THC Table'!H:H,MATCH(C2,'THC
Table'!B:B,0)),IF(H2="20DV",INDEX('THC Table'!D:D,MATCH(C2,'THC
Table'!B:B,0)))))-T2=0,"ok","ERROR")


And here's the VBA code I get when I record the formula as a macro,
which doesn't work (seems like the first "IF" statement doesn't get
recorded):

Range("AC2").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-21]=""40DV"",INDEX('THC
Table'!C[-24],MATCH(RC[-26],'THC
Table'!C[-27],0)),IF(RC[-21]=""40HC"",INDEX('THC
Table'!C[-21],MATCH(RC[-26],'THC
Table'!C[-27],0)),IF(RC[-21]=""20DV"",INDEX('THC
Table'!C[-25],MATCH(RC[-26],'THC Table'!C[-27],0)))))?"
Range("AC2").Select


Please help, thanks.


---
Message posted from http://www.ExcelForum.com/

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA problem, works fine as formula but not in VBA

Hi Frank,

Yes the code works fine, BUT, I get a number as a result, not an "ok
or "ERROR" which is what I would like. The trailling '?' is precisel
what I believe is missing from the formula, namely this part of th
formula -T2=0,"ok","ERROR") which goes together with the first par
of the forumla =IF. When I record a macro its seems to ignore it.

Regards,
Xlun

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA problem, works fine as formula but not in VBA

Seems like the first IF is missing as well with the T2 + rest. (forgo
it when recording?)

Is this working?

"=IF(IF(RC[-21]=""40DV"",INDEX('THC Table'!C[-24],MATCH(RC[-26],'TH
Table'!C[-27],0)),IF(RC[-21]=""40HC"",INDEX('TH
Table'!C[-21],MATCH(RC[-26],'TH
Table'!C[-27],0)),IF(RC[-21]=""20DV"",INDEX('TH
Table'!C[-25],MATCH(RC[-26],'TH
Table'!C[-27],0)))))-RC[-9]=0,"ok","Error"

--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA problem, works fine as formula but not in VBA

e18 it works!!!

Thank you both for your help.

Regards,
Xlun

--
Message posted from http://www.ExcelForum.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
VBA errors in 2007 (works fine in 2003) Horatio J. Bilge, Jr. Excel Discussion (Misc queries) 14 September 6th 09 12:46 PM
Macro hangs up often but sometimes works fine Jeff Excel Worksheet Functions 3 June 13th 06 01:01 PM
VLOOKUP on separate file: Works fine for a while.... Ken Cobler Excel Worksheet Functions 0 September 16th 05 05:18 PM
Macro works fine in xl2002 but does not in xl 2000 Nolin[_2_] Excel Programming 1 February 25th 04 05:58 PM
RPC ERROR - 1ST TIMES WORKS FINE - 2ND TIME ERRORS OUT PoK Excel Programming 0 August 5th 03 08:51 PM


All times are GMT +1. The time now is 04:43 AM.

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"