Applying a function to selected cells

jay starz

New Member
Joined
Nov 30, 2005
Messages
1
Hi,

I'm so glad I found this. This is a very useful service indeed.

Let me get into my question. Assume I have two columns A & B and I have any type of data in both. For example a person's last name in the first column and a person's first name in column B. Now in column C I want to combine the information so that it reads "Last Name, First name."

I know the formula for each cell would be =(Ax&", "&Bx) with x being the cell number. My question is this how do I apply the formula for each of the cells without having to copy and paste for each cell in column C and then putting in the value for 'x' depending on what cell I'm in. For example if I'm in cell C15 x would be 15 using the formula above.

How do I index 'x' and make it go through all the cells required by putting in the answers for each cell?

for(x=1; x<50; x++)
column_C_complete_name_x = column_A_last_name_x, column_B_first_name_x;

I want to do something like above for column C for each of the cells.

Does anyone know how I can do this in excel or if it's possible?

Thanks!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I can't follow how you're trying to do this. Are you trying to use VBA?

If so, you could do a For-Next loop, similar to what you said and begin with your first row and end with your last one. Concatenation will put the formula in appropriatley for you. Something along these lines:

Code:
For myRow = firstRow to lastRow
  myCell = "C" & myRow
  ActiveSheet.Range(myCell).Formula = "=A" & myRow & "&B" & myRow" 
Next myRow

HTH
 
Upvote 0
or you could avoid the loop and do this:

Code:
Sub test()
Range("C1:C50").FormulaR1C1 = "=RC[-2] & " & Chr(34) & ", " & Chr(34) & "& RC[-1]"
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,634
Messages
6,120,659
Members
448,975
Latest member
sweeberry

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top