Macros error

emmmilyvb

New Member
Joined
Jul 28, 2024
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I’m very new to macros. I need to do it for my assessment I’m currently working on.

I’ve created a macro that needs to work across 3 sheets in my workbook. It works on 2 of them but the 3rd states “select method of range class failed” and I don’t know how to fix it. I’ve even tried re-importing the whole worksheet into my workbook to start again but the same error shows, only on this worksheet. Help pls 🥺
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I’m very new to macros. I need to do it for my assessment I’m currently working on.

I’ve created a macro that needs to work across 3 sheets in my workbook. It works on 2 of them but the 3rd states “select method of range class failed” and I don’t know how to fix it. I’ve even tried re-importing the whole worksheet into my workbook to start again but the same error shows, only on this worksheet. Help pls 🥺
Post the macro, and indicate where the error happens.
 
Upvote 0
Sub Cafe_Sales_Data()
'
' Cafe_Sales_Data Macro
'

'
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Rows("1:1").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B2,B4:B21,C4:H4").Select
Range("C4").Activate
Selection.Font.Size = 12
Selection.Font.Size = 14
With Selection.Font
.Color = -1003520
.TintAndShade = 0
End With
With Selection
.HorizontalAlignment = xlLeft
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Font.Italic = True
Selection.Font.Italic = False
Selection.Font.Bold = True
Range("C5:H21").Select
Selection.NumberFormat = "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"
Range("B4:H21").Select
Application.CutCopyMode = False
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$B$4:$H$21"), , xlYes).Name = _
"Table3"
Range("Table3[#All]").Value
ActiveSheet.ListObjects("Table3").TableStyle = "TableStyleLight1"
Range("B17:H17,B19:C21").Select
Range("B19").Activate
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlDouble
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThick
End With
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("D22").Select
End Sub

Above is the macro code (I wasn't sure what you were asking for, as I'm still new to it all). I tried to run the Macro again to show where the error was but now it doesn't even give me the option to run it at all. From memory it was on the section above that I have made bold.
 
Upvote 0
Post the macro, and indicate where the error happens.
Sub Cafe_Sales_Data()
'
' Cafe_Sales_Data Macro
'

'
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Rows("1:1").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B2,B4:B21,C4:H4").Select
Range("C4").Activate
Selection.Font.Size = 12
Selection.Font.Size = 14
With Selection.Font
.Color = -1003520
.TintAndShade = 0
End With
With Selection
.HorizontalAlignment = xlLeft
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Font.Italic = True
Selection.Font.Italic = False
Selection.Font.Bold = True
Range("C5:H21").Select
Selection.NumberFormat = "_($* #,##0.00_);_($* (#,##0.00);_($* ""-""??_);_(@_)"
Range("B4:H21").Select
Application.CutCopyMode = False
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$B$4:$H$21"), , xlYes).Name = _
"Table3"
Range("Table3[#All]").Value
ActiveSheet.ListObjects("Table3").TableStyle = "TableStyleLight1"
Range("B17:H17,B19:C21").Select
Range("B19").Activate
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlDouble
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThick
End With
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("D22").Select
End Sub

Above is the macro code (I wasn't sure what you were asking for, as I'm still new to it all). I tried to run the Macro again to show where the error was but now it doesn't even give me the option to run it at all. From memory it was on the section above that I have made bold.
(I accidentally posted this as a reply to the thread, not to you. Everything's a mess tonight)
 
Upvote 0
The Range("Table3[#All]").Value line is not a stand alone piece of code.
What are you trying to do with this line?
It's not doing anything - maybe you can delete it.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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