+ Reply to Thread
Results 1 to 4 of 4

Thread: First Macro I want to create, can't run it . please help

  1. #1
    Registered User
    Join Date
    01-26-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    8

    Question First Macro I want to create, can't run it . please help

    Hi guys,




    this is the code that VBA created when I recorded a simple macro to make a cell yellowish.

    a syntax error window pop up this is the code generated,
    anyone knows why





    Sub Macro2()
    '
    ' Macro2 Macro
    '

    '
    Wend Selection+Interior
    +Pattern <= xlSolid
    +PatternColorIndex <= xlAutomatic
    +Color <= 65535
    +TintAndShade <= 0
    +PatternTintAndShade <= 0
    ElseIf Wend
    End Sub

  2. #2
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    359

    Re: First Macro I want to create, can't run it . please help

    First - please read the forum rules - all code must be wrapped in CODE tags.

    I have NO idea how the Macro recorder generated the above code - it should be
    sub macro2()
    With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .Color = 65535
            .TintAndShade = 0
            .PatternTintAndShade = 0
    End With
    End Sub
    Try recording it again - Wend is part a loop control structure and there is an End If so there should be a starting IF (conditional statement) - so I have no idea why the recorder did this?? Did you copy and paste the recorded macro into another macro??
    Hope this helps.
    Anthony
    “Confidence never comes from having all the answers; it comes from being open to all the questions.”
    PS: Remember to mark your questions as Solved once you are satisfied and rate the answer(s) questions.”
    Last edited by smuzoen; 01-26-2012 at 08:28 PM.

  3. #3
    Valued Forum Contributor JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    Japan
    MS-Off Ver
    Excel 2010
    Posts
    779

    Re: First Macro I want to create, can't run it . please help

    As per forum rules can you wrap your code in cod tags.

    As for you problem , what exactly are you trying to achieve? If you could post a sample workbook to better describe what you are after, that would help a lot.
    If you are happy with the answer, please click the Star icon in the below left hand corner.

    Good sites to start learning.

    snb's VBA Help Files
    Jerry Beaucaires Excel Assistant
    J & R Excel Consultancy Services

    How to post code correctly: Correct Code Posting

  4. #4
    Registered User
    Join Date
    01-26-2012
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: First Macro I want to create, can't run it . please help

    @smuzoen : I typed the code you wrote me it worked.
    The prosblem is why the recorder is recording like that. it seems to be a bug in the installation, and excel need to be reinstalled.

+ 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.2.0