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.
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
11,469
Office Version
365, 2010
Platform
Windows, Mobile
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
 

TooZippy

Board Regular
Joined
Dec 30, 2018
Messages
70
I will try both suggestions, but it won't be until Monday. Thank you for helping out

Jared Z.
 

Forum statistics

Threads
1,081,678
Messages
5,360,462
Members
400,586
Latest member
Minty

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top