Hi
I display the code below - I am a novice at this and slowly working on building upon it. I have two spreadsheets, one is variable from month to month (called example.xlsx in the below code) and a fixed spreadsheet which consists of a header row that I need the macro to build each month.
So the header spreadsheet has headers called salary, salary adj, car allowance etc. The fixed sheet contains all the amounts for the applicable headers but if there is no salary adj in the current month then I need the fixed spreadsheet to have a zero in those fields. What I normally do is record the macro and make any adjustments manually where there is a problem so the code will be longer than the more experienced.
Please can someone help me with the code - I really appreciate any help at all.
Code below:
Sub parttwo()
Workbooks.Open Filename:= _
"N:\PAYROLL\Leanne\example - Macro Work LB only\Excel Spreadsheet Header Row_amended.xlsx"
'Need to sort this out because it can't find salary adj the macro stops working
Range("S2").Select
Cells.Find(What:="Salary Adj", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Range("T2").Select
Application.CutCopyMode = False
With Selection.Font
.Name = "Microsoft Sans Serif"
.FontStyle = "Regular"
.Size = 8
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 3
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 3
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
With Selection
.HorizontalAlignment = xlRight
.VerticalAlignment = xlTop
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.NumberFormat = "0.00"
ActiveCell.FormulaR1C1 = "0"
Range("T2").Select
Selection.Copy
Range("T2:T30").Select
ActiveSheet.Paste
End sub
Bookmarks