Solved

Placing concatenate in formula in cell

Posted on 2012-04-11
6
258 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
  • 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvieā€¦
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

777 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