Hi
I attach two spreadsheets, one is "Excel Spreadsheet Header Row_1.xlsx" which is a fixed header row that has to stay in the order on the sheet. The other spreadsheet is a variable spreadsheet which changes month to month "example.xlsx". I need the data from the example.xlsx to be copy and pasted into the excel spreadsheet but not all header row items are used.
My problem is when I search for "Salary Adj", because its not in the example.xlsx the macro stops working and I need a bit of code to rectify it. So If the column "Salary Adj" has no data in the example sheet then I want zero's in the cells within the column with the header "Salary Adj" in the Excel Spreadsheet Header Row.xlsx"
Here is a selection of the code below:
Sub parttwo()
Workbooks.Open Filename:= _
"N:\PAYROLL\Leanne\Private - Macro Work LB only\Excel Spreadsheet Header Row_1.xlsx"
'Need to sort this out because it can't find sal adj its displaying an error
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
Not sure that I put the complete piece of the code in, so for car allowance the same thing happens as below
Windows("example.xlsx").Activate
Range("V30").Select
'same for this as car allow and sal adj
Cells.Find(What:="Holiday Pay", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Windows("Excel Spreadsheet Header Row_1.xlsx").Activate
Cells.Find(What:="Holiday Pay", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Range("W2").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("W2").Select
Bookmarks