LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 194
Default Code to enter formula w/ relative row ref? SOLVED

Well, I don't know exactly how it happened, but I stumbled onto the
solution. My code is simply
ActiveCell.FormulaR1C1 = _

"=LEFT(RC[-10]&"".0.0."",FIND(""$"",SUBSTITUTE(RC[-10]&"".0.0."",""."",""$""
,3))-1)"
ActiveCell.Calculate

which is exactly what you gave me that didn't work! (Exactly, except for
the cell references, which were adjusted to get me where I needed to go.)

Here's what happened: someone suggested I have the formula in a cell, the
have my code simply copy and Paste Special Formula, and it would grab the
correct reference. Due to the way I lay out this file, I couldn't have the
formula in there first; it would have to be typed in - which was my problem!
So I tried a previous trick - while the recorder is running, type it in as
text, then click in the formula bar and enter an = sign to make it a
formula. Voila - it came out as above. Since I'm on manual calculation
(which I didn't think of before and might well have been why your answer
"didn't work" for me!!), I added the Calculate, and it all works
beautifully.

Thanks so much for responding to my post.

Ed

"Ed" wrote in message
...
Thanks for replying. But it didn't work. I have my data in column A (A1

is
a header, so data starts in A2). I entered the formula in C9, then turned
on the recorder with relative reference, clicked in the formula bar and

hit
enter. The recorder captured this:

ActiveCell.FormulaR1C1 = _


"=LEFT(R[-7]C[-2]&"".0.0."",FIND(""$"",SUBSTITUTE(R[-7]C[-2]&"".0.0."","".""
,""$"",3))-1)"
ActiveCell.Offset(1, 0).Range("A1").Select

The formula in C9 still points to A2.

Did I do something wrong?

Ed

"Father Guido" wrote in message
...
On Tue, 30 Sep 2003 09:36:00 -0700, "Ed"
wrote:

I have a formula (courtesy of J.E. McGimpsey - thank you!!) as

follows:
=LEFT(A1&".0.0.",FIND("$",SUBSTITUTE(A1&".0.0.",". ","$",3))-1)

I'm trying to create a macro that will enter this in any cell of any

row
and
pick up the ActiveCell row reference. So A1 would be "A &

ActiveCellRow".
I've tried several ways, but get lost in parenthesis, quotes and
double-quotes, and VBA Expected End of Statement errors.

Any assistance is greatly appreciated.

Ed


It depends where the formula is to be entered, for instance, if I enter
your formula in C1 I'd get this...

ActiveCell.FormulaR1C1 = _



"=LEFT(RC[-2]&"".0.0."",FIND(""$"",SUBSTITUTE(RC[-2]&"".0.0."",""."",""$"",3
))-1)"

Just enter the formula, as you stated, in whatever cell it will be
applied to. Turn on the macro recorder, click on relative referencing,
click in the formula on the formula bar, hit enter and then stop the
macro recorder. Copy the formula from the recorded macro to wherever you
need it.

Father Guido
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
I plan on living forever... so far, so good







 
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
Auto Enter after scanning in a Bar Code David Setting up and Configuration of Excel 0 November 30th 07 03:34 AM
Need VBA code to enter text into a textbox !!!! Art Ferdinand Excel Discussion (Misc queries) 1 May 6th 05 01:47 PM
Relative Cell References within VBA code Jandy Excel Discussion (Misc queries) 2 April 21st 05 02:17 AM
ALT + enter or Char(13) in code JL Excel Discussion (Misc queries) 3 April 8th 05 05:27 PM
Enter text in cell Code Kelly[_5_] Excel Programming 5 August 23rd 03 08:47 AM


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