This macro was working but when I put the raw data in the spreadsheet to test it out in worksheet "A", it inserted columns "F" and "G" in worksheet "B" instead. That is all it did. It didn't insert the formulas into columns "F" and "G". The debug box came up and when I went to debug, the part of the macro that highlighted yellow was at the bottom to insert the header name "ABC" in column "F"...
I was thinking that it might have something to do with the """" at the end of the second formula. I am trying to enter a blank space if the condition is false. Could this be the problem?
Thank you,
Jared Z
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]Worksheets("Paste Vendor Data").Range("F2:F1501").Formula = "=IF(LEFT(E2,1)=""-"",MID(E2,2,LEN(E2)),E2)"[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue]Worksheets("Paste Vendor Data").Range("G2:G1501").Formula = "=IF(AND(F2>0,R2>0,S2>0),CONCATENATE(R2,""-"",S2),if(AND(R2>0,S2=0),R2,IF(AND(F2>0,S2=0),F2,IF(AND(F2=0,S2>0),IF(R2>0,CONCATENATE(R2,""-"",S2),S2),""""))))"[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] [/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] Columns("F:F").Select[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] Selection.Copy[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] :=False, Transpose:=False[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] [/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue]Application.ScreenUpdating = False[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] Dim cell As Range[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] ActiveSheet.Cells.Replace what:=Chr(160), Replacement:=Chr(32), _[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] On Error Resume Next 'in case no text cells in selection[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] For Each cell In ActiveSheet.Cells.SpecialCells(xlConstants, xlTextValues)[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] cell.Value = Application.Trim(cell.Value)[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] Next cell[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] On Error GoTo 0[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] Application.ScreenUpdating = True[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] [/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] Columns("G:G").Select[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] Application.CutCopyMode = False[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] Selection.Copy[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] :=False, Transpose:=False[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] [/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] Range("A1").End(xlToRight).Offset(0, 1).Value = "ABC"[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] [/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] MsgBox ("Done!")[/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue] [/FONT][/COLOR]
[COLOR=#26282A][FONT=Helvetica Neue]End Sub[/FONT][/COLOR][/LEFT]
I was thinking that it might have something to do with the """" at the end of the second formula. I am trying to enter a blank space if the condition is false. Could this be the problem?
Thank you,
Jared Z