Results 1 to 3 of 3

Using a MATCH in VBA is driving me crazy!

Threaded View

zookeepertx Using a MATCH in VBA is... 01-13-2015, 02:11 PM
sktneer Re: Using a MATCH in VBA is... 01-13-2015, 02:38 PM
zookeepertx Re: Using a MATCH in VBA is... 01-13-2015, 03:00 PM
  1. #1
    Forum Contributor
    Join Date
    06-25-2013
    Location
    Longview, TX
    MS-Off Ver
    MS365
    Posts
    338

    Using a MATCH in VBA is driving me crazy!

    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
    Attached Files Attached Files
    Last edited by zookeepertx; 01-13-2015 at 02:18 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Match function works while the "=" says True! Driving me crazy!
    By tony.nz in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-21-2014, 02:17 PM
  2. This is driving me crazy!!
    By rtausch in forum Excel General
    Replies: 0
    Last Post: 10-15-2008, 06:33 PM
  3. please please help driving me crazy
    By jilly jess in forum Excel General
    Replies: 1
    Last Post: 01-14-2007, 09:59 AM
  4. Formula is driving me crazy?????
    By Chris Watson in forum Excel Formulas & Functions
    Replies: 19
    Last Post: 02-13-2006, 03:20 PM
  5. Driving me crazy!
    By RobEdgeler in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-03-2005, 05:19 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1