Solved

Placing concatenate in formula in cell

Posted on 2012-04-11
6
260 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

840 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