VBA Debugging: Range select breaks my first macro

VRM

New Member
Joined
Jun 27, 2020
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hi,
Novice with no VBA coding skills.
The actual macro is long, so I am posting to the point where the debugger stops.
I have put the macro in "my personal workbook" so I that I can use in other workbooks.
VBA Code:
    Columns("H:H").Select
    Selection.Cut
    Columns("G:G").Select
    Selection.Insert Shift:=xlToRight
    Columns("J:P").Select
    Selection.Style = "Percent"
    Range("A1:P8").Select
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$P$8"), , xlYes).Name = _
        "Table7"
    Range("Table7[#All]").Select
Any assistance would be appreciated. Thanks.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try avoiding selecting, most of the time it is not required and slows the code
VBA Code:
    Columns("H:H").Cut
    Columns("G:G").Insert Shift:=xlToRight
    Columns("J:P").Style = "Percent"
    'Range("A1:P8").Select
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$P$8"), , xlYes).Name = _
        "Table7"
    Range("Table7[#All]").Select
 
Upvote 0
Solution
Thank you were correct, the Select was not needed.

Now as I step through, I hit another error. I am going to post all of the code.
And, yes I know some of the steps are defaults, but I am nervous and still learning.
Now my problem line is: Range("Table7[[#Headers],[Abt Organization]]").Select

VBA Code:
    Columns("H:H").Select
    Selection.Cut
    Columns("G:G").Select
    Selection.Insert Shift:=xlToRight
    Columns("J:P").Select
    Selection.Style = "Percent"
    Range("A1:P8").Select
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$P$8"), , xlYes).Name = _
        "Table7"
    ActiveSheet.ListObjects("Table7").TableStyle = "TableStyleLight21"
    ActiveSheet.ListObjects("Table7").ShowAutoFilterDropDown = False
  [COLOR=rgb(184, 49, 47)][B]  Range("Table7[[#Headers],[Abt Organization]]").Select[/B][/COLOR]
    ActiveCell.FormulaR1C1 = "Abt " & Chr(10) & "Organization"
    Range("Table7[[#Headers],[Count of Projects]]").Select
    ActiveCell.FormulaR1C1 = "Count" & Chr(10) & "of Projects"
    Range("Table7[[#Headers],[Projects with Proposal Doc ""Pass"" Status]]").Select
    ActiveCell.FormulaR1C1 = "Projects with " & Chr(10) & "Proposal Doc"
    Range("Table7[[#Headers],[Projects with Project Doc ""Pass"" Status]]").Select
    ActiveCell.FormulaR1C1 = "Projects with " & Chr(10) & "Project Doc"
    Range("Table7[[#Headers],[Projects with Project Descriptions]]").Select
    ActiveCell.FormulaR1C1 = "Projects with " & Chr(10) & "Project Descriptions"
    Range("Table7[[#Headers],[Projects with At Least One Key Level Tag]]").Select
    ActiveCell.FormulaR1C1 = "Projects with " & Chr(10) & "At Least One Tag"
    Range("Table7[[#Headers],[Complete Projects]]").Select
    ActiveCell.FormulaR1C1 = "Complete " & Chr(10) & "Projects"
    Range("Table7[[#Headers],[Partial Projects]]").Select
    ActiveCell.FormulaR1C1 = "Partial " & Chr(10) & "Projects"
    Range("Table7[[#Headers],[Incomplete Projects]]").Select
    ActiveCell.FormulaR1C1 = "Incomplete " & Chr(10) & "Projects"
    Range("Table7[[#Headers],[Proposal Doc %]]").Select
    ActiveCell.FormulaR1C1 = "Proposal " & Chr(10) & "Doc %"
    Range("Table7[[#Headers],[Project Doc %]]").Select
    ActiveCell.FormulaR1C1 = "Project " & Chr(10) & "Doc %"
    Range("Table7[[#Headers],[Project Description %]]").Select
    ActiveCell.FormulaR1C1 = "Project " & Chr(10) & "Description %"
    Range("Table7[[#Headers],[Key Level Tags %]]").Select
    ActiveCell.FormulaR1C1 = "Tags %"
    Range("Table7[[#Headers],[Complete Projects %]]").Select
    ActiveCell.FormulaR1C1 = "Complete " & Chr(10) & "Projects %"
    Range("Table7[[#Headers],[Partial Projects %]]").Select
    ActiveCell.FormulaR1C1 = "Partial " & Chr(10) & "Projects %"
    Range("Table7[[#Headers],[Incomplete Projects %]]").Select
    ActiveCell.FormulaR1C1 = "Incomplete " & Chr(10) & "Projects %"
    Columns("A:P").Select
    Selection.ColumnWidth = 13
    ActiveWindow.ScrollColumn = 5
    ActiveWindow.ScrollColumn = 4
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 1
    Columns("E:F").Select
    Selection.ColumnWidth = 19
    Rows("1:1").Select
    With Selection
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlTop
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    With Selection
        .HorizontalAlignment = xlRight
        .VerticalAlignment = xlTop
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Range("Table7[[#Headers],[Abt " & Chr(10) & "Organization]]").Select
    With Selection
        .HorizontalAlignment = xlLeft
        .VerticalAlignment = xlTop
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Range("B2:B8,B1,G2:G8,G1,G1,N2:N8,N1").Select
    Range("Table7[[#Headers],[Complete " & Chr(10) & "Projects %]]").Activate
    With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
 
Upvote 0
What does changing
VBA Code:
Range("Table7[[#Headers],[Abt Organization]]").Select
ActiveCell.FormulaR1C1 = "Abt " & Chr(10) & "Organization"
to
VBA Code:
Range("Table7[[#Headers],[Abt Organization]]").Value = "Abt " & Chr(10) & "Organization"
do for you?

Btw, if you want to format code manually (i.e. your bold and color) in posts then you need to use <rich/> code tags rather than <vba/> tags ;)
 
Upvote 0
Hi.
I seem to be all set.
My original code with the Select removed as you suggested does work.
I needed to run the macro on a clean, un-formatted version of the spreadsheet.
How do I "close" this thread since my issue as been resolved?
Thanks.
 
Upvote 0
You don't need to do anything to close the thread, you just say thanks (which you have already done).
Happy that you have it sorted and welcome to the board.
 
Upvote 0

Forum statistics

Threads
1,214,817
Messages
6,121,717
Members
449,050
Latest member
MiguekHeka

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