I have been trying to use a MATCH function as part of my macro and can NOT get the syntax right. Or else I've created a bigger issue; I'm not sure which. I'll attach a workbook - The first page is how I start out and the second page is how I need to end up. I've got the 4 rows inserting at the top and got them formatting correctly. I need to ultimately have a SUMIF fill the cells in row 3 with the results summing column J. (Apparel and GOH are combined and Flat and Security Mark are combined), but I THINK that, in order to do that, I need to specify the end of each section, to tell the SUMIF where to stop looking, right? That's where I'm running into the problem.
I'm trying to use MATCH to get the row # of the end of each of the sections: Apparel, Cosmetic, etc. If I put a MATCH formula in a cell on the worksheet it works fine. I've tried to translate it into VBA, but am failing miserably. Here is my current, non-working code:
Sub MarkingClosed()
' MarkingClosed
' Jenny01132015
Rows("1:4").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A2:L2").Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
End With
Range("A1:C3,D1:F3,G1:I3,J1:L3").Select
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = xlAutomatic
.Weight = xlMedium
End With
Range("A1:C1,D1:F1,G1:I1,J1:L1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.MergeCells = True
End With
Range("A2:C3,D2:F3,G2:I3,J2:L3").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
End With
Range("A3:L3").Select
Selection.NumberFormat = "0"
Range("A1:C1").Value = "Apparel Y"
Range("D1:F1").Value = "Apparel N"
Range("G1:I1").Value = "Flat/Security Mark"
Range("J1:L1").Value = "Cosmetics"
Range("A2,D2,G2,J2").Value = "A"
Range("B2,E2,H2,K2").Value = "B"
Range("C2,F2,I2,L2").Value = "C"
Range("A3").Select
lr = Range("A" & Rows.Count).End(xlUp).Row
On Error Resume Next
LA = Application.Match(APPAREL, Range("A9:A" & lr), 0)
LC = Application.Match(COSMETICS, Range("A9:A" & lr), 0)
End Sub
( I just thought I'd try to get it to identify the first 2 sections before carrying on to the rest of them).
The problem comes at the 2 red lines. I've tried changing the syntax to EVERY option I can imagine and, every time I change it, I get a different error message! When I F8 through the current code gives a 2042 error on both of those lines.
I've been googling for probably 2 hrs and am no closer to an answer. 
Can anyone see the (probably simple) error I'm making?
Thanks!
Jenny
Bookmarks