Created
November 25, 2013 15:32
-
-
Save Palmr/7643101 to your computer and use it in GitHub Desktop.
VBA to deal with some stock control stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Attribute VB_Name = "Module1" | |
Sub Stockreport1() | |
Attribute Stockreport1.VB_ProcData.VB_Invoke_Func = " \n14" | |
' Comments start with apostrophes :) | |
' Select a bunch of columns, then remove them | |
Range("F:F,I:I,X:X,AD:AD,AE:AE,AA:AC,AH:AP").Select | |
Selection.Delete Shift:=xlToLeft | |
' Insert a new column and put "Stores OOS" in the first item to be the title | |
Columns("J:J").Select | |
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove | |
Range("J1").Select | |
ActiveCell.FormulaR1C1 = "Stores OOS" | |
' Fill it full of formula goodness | |
Range("J2").Select | |
With Sheets("Sheet1") | |
Dim LastRow As Long | |
LastRow = Range("A" & Rows.Count).End(xlUp).Row | |
With Range("J2") | |
ActiveCell.FormulaR1C1 = "=((100-RC[-1])/100)*RC[-2]" | |
.AutoFill Destination:=Range("J2:J" & LastRow) | |
End With | |
End With | |
Range("J2").Select | |
Selection.AutoFill Destination:=Range("J2:J" & LastRow) | |
' Set a number format for the column over the rows we just filled | |
Range("J2:J" & LastRow).Select | |
Selection.NumberFormat = "0" ' This number format means no decimal places, change to 0.00 or whatever if you want more info | |
' Autofit all columns, makes the titles visible | |
Columns("A:ZZ").EntireColumn.AutoFit | |
' Make sure we didn't end up scolled somewhere weird | |
ActiveWindow.ScrollColumn = 1 | |
' Select the top left cell | |
Range("A1").Select | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment