Converting function to macro

bookworm121

New Member
Joined
Jun 22, 2011
Messages
39
So i need to get these function into a macro so that no matter what the size of the spreadsheet it loops till the very end. I have the logic figured out I just need help writing the actual code.

Assume x is the row number... so is we're at Ax this means we're in cell A2 while if we're at Ax-1 we're in A1 for that example...

We have 2 columns C and D that are pre-filled.

In column E's first cell I need this function: =if(c1="",D1&" "&D2, D1)
in the rest of column E's cells I need this function: = if(Cx-1<>"",Dx,Ex-1&" "&Dx)

In column F i need this function: =if(Cx="","",Ex) for all the cells

Then I need to delete both columnd D and E

any help would be wonderful! thanks
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try something like this...
Code:
Dim Lastrow As Long
Lastrow = Range("C" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
Range("E1").Formula = "=IF(C1="""",D1&"" ""&D2, D1)"
[COLOR="Red"][COLOR="Red"]Range("E2:E" & Lastrow).FormulaR1C1 = "=IF(R[-1]C3<>"""",RC4,R[-1]C5&"" ""&RC4)"[/COLOR][/COLOR]
Range("F1:F" & Lastrow).FormulaR1C1 = "=IF(RC3="""","""",RC5)"
Range("F1:F" & Lastrow).Value = Range("F1:F" & Lastrow).Value
Range("D1:E" & Lastrow).ClearContents
Application.ScreenUpdating = True
 
Last edited:
Upvote 0
huh... that actually works!
it creates a very messy result, but totally fixable :)
THANKS A LOT!


Try something like this...
Code:
Dim Lastrow As Long
Lastrow = Range("C" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
Range("E1").Formula = "=IF(C1="""",D1&"" ""&D2, D1)"
[COLOR=red][COLOR=red]Range("E2:E" & Lastrow).FormulaR1C1 = "=IF(R[-1]C3<>"""",RC4,R[-1]C5&"" ""&RC4)"[/COLOR][/COLOR]
Range("F1:F" & Lastrow).FormulaR1C1 = "=IF(RC3="""","""",RC5)"
Range("F1:F" & Lastrow).Value = Range("F1:F" & Lastrow).Value
Range("D1:E" & Lastrow).ClearContents
Application.ScreenUpdating = True
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,550
Members
452,927
Latest member
rows and columns

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