![]() |
Macro- Column Insert
After recording a macro that inserts a column in a worksheet, I run it and it
inserts two columns. I don't understand why? |
Macro- Column Insert
"lostatlewisu" wrote: After recording a macro that inserts a column in a worksheet, I run it and it inserts two columns. I don't understand why? Sub Problem() ' ' Problem Macro ' Macro recorded 8/16/2007 ' ' Keyboard Shortcut: Ctrl+Shift+P ' Columns("E:H").Select Selection.Delete Shift:=xlToLeft Columns("G:G").Select Range("G2").Activate Selection.Insert Shift:=xlToRight Range("G2").Select ActiveCell.FormulaR1C1 = "new one" With ActiveCell.Characters(Start:=1, Length:=7).Font .Name = "Arial" .FontStyle = "Bold" .Size = 8 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With Range("G3").Select End Sub |
Macro- Column Insert
Were the columns grouped (via data|group) or did you have merged cells?
lostatlewisu wrote: On the spreadsheet that I was working with columns had been grouped. After I ungrouped them the macro worked to only insert one column. Thanks for your help. "Toppers" wrote: It doesn't insert two columns: it deletes 4 (E:H), moves G2 to H2, adds the text "new one" to G2. Perhaps this: Sub Problem() ' ' Problem Macro ' Macro recorded 8/16/2007 ' ' Keyboard Shortcut: Ctrl+Shift+P ' Columns("E:H").Delete Shift:=xlToLeft Columns("G:G").Insert Shift:=xlToRight Range("G2").FormulaR1C1 = "new one" With Range("G2").Characters(Start:=1, Length:=7).Font .Name = "Arial" .FontStyle = "Bold" .Size = 8 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With End Sub "lostatlewisu" wrote: "lostatlewisu" wrote: After recording a macro that inserts a column in a worksheet, I run it and it inserts two columns. I don't understand why? Sub Problem() ' ' Problem Macro ' Macro recorded 8/16/2007 ' ' Keyboard Shortcut: Ctrl+Shift+P ' Columns("E:H").Select Selection.Delete Shift:=xlToLeft Columns("G:G").Select Range("G2").Activate Selection.Insert Shift:=xlToRight Range("G2").Select ActiveCell.FormulaR1C1 = "new one" With ActiveCell.Characters(Start:=1, Length:=7).Font .Name = "Arial" .FontStyle = "Bold" .Size = 8 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With Range("G3").Select End Sub -- Dave Peterson |
Macro- Column Insert
Hi Dave,
I don't know. I just know that when I clicked (while recording the macro) th tool bar button for merge and center, the columns were ungrouped and the marco only inserted one column on the playback. ;0) "Dave Peterson" wrote: Were the columns grouped (via data|group) or did you have merged cells? lostatlewisu wrote: On the spreadsheet that I was working with columns had been grouped. After I ungrouped them the macro worked to only insert one column. Thanks for your help. "Toppers" wrote: It doesn't insert two columns: it deletes 4 (E:H), moves G2 to H2, adds the text "new one" to G2. Perhaps this: Sub Problem() ' ' Problem Macro ' Macro recorded 8/16/2007 ' ' Keyboard Shortcut: Ctrl+Shift+P ' Columns("E:H").Delete Shift:=xlToLeft Columns("G:G").Insert Shift:=xlToRight Range("G2").FormulaR1C1 = "new one" With Range("G2").Characters(Start:=1, Length:=7).Font .Name = "Arial" .FontStyle = "Bold" .Size = 8 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With End Sub "lostatlewisu" wrote: "lostatlewisu" wrote: After recording a macro that inserts a column in a worksheet, I run it and it inserts two columns. I don't understand why? Sub Problem() ' ' Problem Macro ' Macro recorded 8/16/2007 ' ' Keyboard Shortcut: Ctrl+Shift+P ' Columns("E:H").Select Selection.Delete Shift:=xlToLeft Columns("G:G").Select Range("G2").Activate Selection.Insert Shift:=xlToRight Range("G2").Select ActiveCell.FormulaR1C1 = "new one" With ActiveCell.Characters(Start:=1, Length:=7).Font .Name = "Arial" .FontStyle = "Bold" .Size = 8 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With Range("G3").Select End Sub -- Dave Peterson |
Macro- Column Insert
That's merged cells.
They're a pain for lots of things. lostatlewisu wrote: Hi Dave, I don't know. I just know that when I clicked (while recording the macro) th tool bar button for merge and center, the columns were ungrouped and the marco only inserted one column on the playback. ;0) "Dave Peterson" wrote: Were the columns grouped (via data|group) or did you have merged cells? lostatlewisu wrote: On the spreadsheet that I was working with columns had been grouped. After I ungrouped them the macro worked to only insert one column. Thanks for your help. "Toppers" wrote: It doesn't insert two columns: it deletes 4 (E:H), moves G2 to H2, adds the text "new one" to G2. Perhaps this: Sub Problem() ' ' Problem Macro ' Macro recorded 8/16/2007 ' ' Keyboard Shortcut: Ctrl+Shift+P ' Columns("E:H").Delete Shift:=xlToLeft Columns("G:G").Insert Shift:=xlToRight Range("G2").FormulaR1C1 = "new one" With Range("G2").Characters(Start:=1, Length:=7).Font .Name = "Arial" .FontStyle = "Bold" .Size = 8 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With End Sub "lostatlewisu" wrote: "lostatlewisu" wrote: After recording a macro that inserts a column in a worksheet, I run it and it inserts two columns. I don't understand why? Sub Problem() ' ' Problem Macro ' Macro recorded 8/16/2007 ' ' Keyboard Shortcut: Ctrl+Shift+P ' Columns("E:H").Select Selection.Delete Shift:=xlToLeft Columns("G:G").Select Range("G2").Activate Selection.Insert Shift:=xlToRight Range("G2").Select ActiveCell.FormulaR1C1 = "new one" With ActiveCell.Characters(Start:=1, Length:=7).Font .Name = "Arial" .FontStyle = "Bold" .Size = 8 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = xlAutomatic End With Range("G3").Select End Sub -- Dave Peterson -- Dave Peterson |
All times are GMT +1. The time now is 02:38 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com