Macro Stopped Working

TooZippy

Board Regular
Joined
Dec 30, 2018
Messages
70
I tried to merge three macros into one to conserve steps, and it worked at first. I combined this macro with a copy/paste special/value macro and a delete contents of empty cells in a column.

Code:
[LEFT][COLOR=#26282A][FONT=Helvetica Neue]Sub MergeColumns()[/FONT][/COLOR]

[COLOR=#26282A][FONT=Helvetica Neue]Columns("F:G").Insert[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue]Range("F2:F" & Range("E2").End(xlDown).Row).Formula = "=IF(LEFT(E2,1)=""-"",MID(E2,2,LEN(E2)),E2)"[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue]Range("G2:G" & Range("F2").End(xlDown).Row).Formula = "=IF(AND(F2>0,S2>0),F2,IF(AND(F2>0,S2=0),F2,IF(AND(F2=0,S2>0),IF(R2>0,CONCATENATE(R2,""-"",S2),S2),0)))"[/FONT][/COLOR]

[COLOR=#26282A][FONT=Helvetica Neue]End Sub[/FONT][/COLOR][/LEFT]

It worked at first. Then I deleted the two columns that were inserted with the formulas pasted in them to start over again. I ran the macro again and it inserted the two columns but only pasted the two formulas in the first two rows. It was empty below these rows. I can not figure out what I did wrong. Can you help me out please?

Thank you,

Jared Z.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Do you have any blank cells below row 2?

Perhaps try...

Code:
Sub MergeColumns()

Columns("F:G").Insert
Range("F2:F" & Range("F" & Rows.Count).End(xlUp).Row).Formula = "=IF(LEFT(E2,1)=""-"",MID(E2,2,LEN(E2)),E2)"
Range("G2:G" & Range("G" & Rows.Count).End(xlUp).Row).Formula = "=IF(AND(F2>0,S2>0),F2,IF(AND(F2>0,S2=0),F2,IF(AND(F2=0,S2>0),IF(R2>0,CONCATENATE(R2,""-"",S2),S2),0)))"

End Sub

or

Code:
Sub MergeColumns()

Columns("F:G").Insert
Range("F2:F" & Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row).Formula = "=IF(LEFT(E2,1)=""-"",MID(E2,2,LEN(E2)),E2)"
Range("G2:G" & Cells.Find("*", , xlValues, , xlByRows, xlPrevious).Row).Formula = "=IF(AND(F2>0,S2>0),F2,IF(AND(F2>0,S2=0),F2,IF(AND(F2=0,S2>0),IF(R2>0,CONCATENATE(R2,""-"",S2),S2),0)))"

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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