Solved

Placing concatenate in formula in cell

Posted on 2012-04-11
6
257 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

912 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now