+ Reply to Thread
Results 1 to 8 of 8

VBA Compile Error: Expected End With

Hybrid View

  1. #1
    Registered User
    Join Date
    02-08-2011
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2007
    Posts
    16

    Question VBA Compile Error: Expected End With

    I'm am VERY new to VBA and I'm trying to create a user form for document control of specifications. I made the form and tried to run the code and I keep getting a Compile Error. Can anyone tell me how to fix this? Please dumb it down for me, because I need it explained like I'm 6.

    Thank you!

    Mich
    Last edited by MLS Packer Lover; 11-23-2011 at 04:25 PM.
    Mich

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: VBA Compile Error: Expected End With

    hi MLS Packer Lover

    With the "Compile Error" you have one "End With " Missing
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Registered User
    Join Date
    02-08-2011
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: VBA Compile Error: Expected End With

    I fixed that, but when I debug it, I still get an error.

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: VBA Compile Error: Expected End With

    Dude what error which line

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA Compile Error: Expected End With

    Hi MLS Packer Lover
    I've looked at your code...it appears you have more than one End If statements missing. See this link
    http://www.techonthenet.com/excel/formulas/if_then.php
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: VBA Compile Error: Expected End With

    Nest your code; then you can see where you need End Ifs and Loops

    Private Sub cmdOK_Click()
        ActiveWorkbook.Sheets("Change Request Form").Activate
        Range("A1").Select
    Do
        If IsEmpty(ActiveCell) = False Then
            ActiveCell.Offset(1, 0).Select
        End If
        
    Loop Until IsEmpty(ActiveCell) = True
    
            ActiveCell.Value = txtCCTC.Value
            ActiveCell.Offset(0, 2) = txtCustomer.Value
            ActiveCell.Offset(0, 3) = txtInitiator.Value.Value
            ActiveCell.Offset(0, 4) = txtDocumentAffected.Value
        
            If optScrapReduction = True Then
                ActiveCell.Offset(0, 5).Value = "Scrap Reduction"
            ElseIf optLaborReduction = True Then
                ActiveCell.Offset(0, 5).Value = "Labor Reduction"
            ElseIf optVariationReduction = True Then
                ActiveCell.Offset(0, 5).Value = "Variation Reduction"
            ElseIf optCustomerSpecificationChange = True Then
                ActiveCell.Offset(0, 5).Value = "Customer Specification Change"
            ElseIf optReworkReduction = True Then
                ActiveCell.Offset(0, 5).Value = "Rework Reduction"
            ElseIf optMaterialReduction = True Then
                ActiveCell.Offset(0, 5).Value = "Material Reduction"
            ElseIf optEditorial = True Then
                ActiveCell.Offset(0, 5).Value = "Editorial"
            ElseIf optOther = True Then
                ActiveCell.Offset(0, 6).Value = "Other"
            End If
        
            If chkYes = True Then
                ActiveCell.Offset(0, 10).Value = "Yes"
            ElseIf chkNo = True Then
                ActiveCell.Offset(0, 10).Value = "No"
            End If
        
            If chkYes = True Then
                ActiveCell.Offset(0, 11).Value = "Yes"
            Else
                ActiveCell.Offset(0, 11).Value = "No"
            End If
            
            If chkYes = True Then
                ActiveCell.Offset(0, 13).Value = "Yes"
            Else
                ActiveCell.Offset(0, 13).Value = "No"
                
                If chkYes = True Then
                    ActiveCell.Offset(0, 13).Value = "Yes"
                Else
                    ActiveCell.Offset(0, 14).Value = "No"
        
                    If chkYes = True Then
                        ActiveCell.Offset(0, 14).Value = "Yes"
                    Else
                        ActiveCell.Offset(0, 14).Value = "No"
                    End If
        
        Range("A1").Select
    
    End Sub

    I'd say you're missing a couple of End If statements

    Regards
    Last edited by TMS; 11-23-2011 at 06:44 PM.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,943

    Re: VBA Compile Error: Expected End With

    I'm a little confused by the Initialize code which is where there is/are an error(s).

    You don't seem to have a clear understanding of how to use With ... End With.

    This construct is where you have an object, for example, a cell, and you want to do something to several of its properties.

    You could, for example, say:

    With Range("D5")
        .FormulaR1C1 = "x"
        .Font.Bold = True
        .Font.Italic = True
        With .Font
            .Color = -16776961
            .TintAndShade = 0
        End With
    End With

    You seem to be using it with variables, though I have to admit I'm not 100% sure of what is going on.

    Regards

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: VBA Compile Error: Expected End With

    There's several End Ifs & End Withs missing. You should go through the code & make sure that every IF & With statement is closed
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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