Solved

Placing concatenate in formula in cell

Posted on 2012-04-11
6
263 Views
Last Modified: 2012-04-11
Good day!
I am trying to place a concatenate formula into a cell. It needs to pull the number from the cell above, and add a dot and the incremental number from the For Next  (  "i" in the formula.  But I can'tseem to get the right combinations of parenthesis to make it work.  Any help?


"i" is the increment.
A number is in the cell R[-1]C above. ie "9".
The result should be   9.1  and the next time through 9.2   etc.

     ActiveCell.Offset(1, 2).Select
     ActiveCell.FormulaR1C1 = "=(CONCATENATE(R[-1]C,""."" & i & ""))"

BTW (My browser won't let me select a lower point value, so enjoy the 500 points for this question!)
0
Comment
Question by:RayLBailey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 37833828
ActiveCell.FormulaR1C1 = "=CONCATENATE(R[-1]C,"".""," & i & ")"
0
 
LVL 81

Expert Comment

by:byundt
ID: 37833832
If you are trying to loop down a column, then you might need to get the integer value of the cell above before concatenating, such as with:
ActiveCell.FormulaR1C1 = "=CONCATENATE(INT(--R[-1]C),"".""," & i & ")"
0
 

Author Closing Comment

by:RayLBailey
ID: 37833865
Cool Beans!  The first one works like a charm.  Now that I see what you did it makes sense.
Thank you!

Ray
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 81

Expert Comment

by:byundt
ID: 37833938
Ray,
When I am trying to put a formula in a cell, I often get things bollixed. To help debug, I use a string variable for the formula. That way, I can look at the formula in the Immediate pane of the VBA Editor.

For example, you might be testing the following code:
Dim frmla As String
frmla = "=(CONCATENATE(R[-1]C,""."" & i & ""))"
ActiveCell.FormulaR1C1 = frmla              'Put a stop in the code at this statement

To put a stop in the code, click in margin to left of the statement and a big maroon dot will then appear. When you run your macro, execution will stop just before executing this statement--and you will be dumped into the VBA Editor.

To use the Immediate pane, first make sure it is displayed using the View...Immediate pane menu item. You can then evaluate a calculation with:
? "=(CONCATENATE(R[-1]C,""."" & i & ""))"      (hit Enter to make the statement evaluate)

You can also hover the cursor over a variable to see its value.

Either way, you'll see that a valid string is being created--but not one that looks like a worksheet formula. You can then adjust the code to get matters under control.

Brad
0
 

Author Comment

by:RayLBailey
ID: 37834281
Okay,
For the first time I understand how the Immediate Pane works. I tried it a while back and couldn't figure it out.

Yes, I often use a test string or variable to track how something works, but with the Immediate Pane it makes it so much easier.

Here's a swig of my coffee to you!

Ray
0
 
LVL 81

Expert Comment

by:byundt
ID: 37834395
Ray,
With the immediate pane, you can have multiple statements on the same line. Separate each one by a colon.
frmla = "=(CONCATENATE(R[-1]C,""."" & i & ""))" : ?frmla

The first statement puts the result of the string expression into variable frmla. The second statement displays the value.

In a pinch, I have even done complete For...Next loops in the Immediate pane:
For i = 1 To 28 : Cells(i, 1).Value = Environ(i) : Next             'Lists the Environ parameter and its value

Brad
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question