Is this worth cleaning up, or better to re-write?

nutritiouspig

Well-known Member
Joined
Jan 8, 2003
Messages
615
I'm extremely new to VBA (just got a book on it), and was wondering if this would be easy to rewrite, or if there were some quick fixes that could be applied to it, in order to make it run a bit more efficiently.

Thanks,
S.


Sub Format()

Sheets("Output_Sheet").Select
Range("A1:K82").Select
Selection.Delete
Sheets("Data_Sheet").Select
Columns("A:A").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Output_Sheet").Select
Range("A1").Select
ActiveSheet.Paste
Range("A1:A27,A29:A31,A59:A74").Select
Range("A59").Activate
Application.CutCopyMode = False
Selection.Delete
Range("A1:A34").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(28, 1), Array(49, 1), Array(55, 1), Array(60, 1))
Selection.Delete Shift:=xlToLeft
Columns("A:A").EntireColumn.AutoFit
Range("F34").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-32]C[-2]:R[-25]C[-2],R[-23]C[-2]:R[-1]C[-2])"
Range("G34").Select
ActiveCell.FormulaR1C1 = "=0.295-RC[-1]"
Range("G34").Select
Selection.NumberFormat = "0.00%"
Range("F33").Select
ActiveCell.FormulaR1C1 = "Total Shrinkage Used"
Range("G33").Select
ActiveCell.FormulaR1C1 = "Shrinkage Available"
Range("F33:G34").Select
With Selection
.HorizontalAlignment = xlCenter
End With
Columns("F:G").EntireColumn.AutoFit
Range("F34").Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
Formula1:="0.295"
With Selection.FormatConditions(1).Font
.Bold = True
.ColorIndex = 2
End With
Selection.FormatConditions(1).Interior.ColorIndex = 3
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
Formula1:="0.295"
With Selection.FormatConditions(2).Font
.Bold = True
.ColorIndex = 1
End With
Selection.FormatConditions(2).Interior.ColorIndex = 35
Range("G34").Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
Formula1:="0"
With Selection.FormatConditions(1).Font
.Bold = True
.ColorIndex = 1
End With
Selection.FormatConditions(1).Interior.ColorIndex = 35
Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, _
Formula1:="0"
With Selection.FormatConditions(2).Font
.Bold = True
.ColorIndex = 2
End With
Selection.FormatConditions(2).Interior.ColorIndex = 3
With Range("F33:G34").Select
With Selection.Borders
.LineStyle = xlContinuous
.Weight = xlThin
End With
End With
End Sub
 

Some videos you may like

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

north19701

Active Member
Joined
Jun 17, 2003
Messages
491
Generally, there's no need to select the range. For example, the first three lines of your code:

Code:
Sheets("Output_Sheet").Select 
Range("A1:K82").Select 
Selection.Delete

can be shortened to:

Code:
Sheets("Output_Sheet").Range("A1:K82").Delete
 

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,028
For more ideas along these lines see the Excel/VBA/Beyond Excel's recorder page of my web site.
north19701 said:
Generally, there's no need to select the range. For example, the first three lines of your code:
 

Watch MrExcel Video

Forum statistics

Threads
1,123,385
Messages
5,601,331
Members
414,446
Latest member
CRAVIN

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
Top