Help with this code

help_questions

Board Regular
Joined
Aug 22, 2005
Messages
215
Below is a part of my existing VBA code. It works perfectly. As many of you know at first glance, this code was created using the macro recorder. I want to shorten the code, but not sure how. I know that many of the commands should be done with one command , but i am not experienced enough to understand how/why? Can someone help? Here is the code:
.....
Cells.Select
Cells.EntireColumn.AutoFit
ActiveWindow.SmallScroll ToRight:=7
Columns("K:W").Select
Selection.Delete Shift:=xlToLeft
Columns("AK:CD").Select
Selection.Delete Shift:=xlToLeft
Range("AL:AL,AN:AN,AP:AP,AQ:AQ,AS:AS").Select
Range("AS1").Activate
ActiveWindow.SmallScroll ToRight:=3
Range("AL:AL,AN:AN,AP:AP,AQ:AQ,AS:AS,AU:AU").Select
Range("AU1").Activate
Selection.Delete Shift:=xlToLeft
Range("A1").Select
Range("X:AJ").Select
Selection.Delete Shift:=xlToLeft
Range("A1").Select
Range("D5:J5").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
Columns("G:G").Select
Selection.Delete Shift:=xlToLeft
Columns("H:H").Select
Selection.Delete Shift:=xlToLeft
Selection.Delete Shift:=xlToLeft
Range("D5:G5").Select
Range("G5").Activate
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
1st thing is lose all the scrolling code like this.
Code:
 ActiveWindow.SmallScroll ToRight:=7
2nd thing lose the selection code.

eg This
Code:
Cells.Select
Cells.EntireColumn.AutoFit
ActiveWindow.SmallScroll ToRight:=7
Columns("K:W").Select
Selection.Delete Shift:=xlToLeft
Can be replaced with this.
Code:
Cells.EntireColumn.AutoFit
Columns("K:W").Delete Shift:=xlToLeft
 
Upvote 0

Forum statistics

Threads
1,215,583
Messages
6,125,664
Members
449,247
Latest member
wingedshoes

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