+ Reply to Thread
Results 1 to 6 of 6

first timer using VB to cut and paste macro - getting compile error syntax error

Hybrid View

  1. #1
    Registered User
    Join Date
    10-24-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    7

    first timer using VB to cut and paste macro - getting compile error syntax error

    Hi everyone,

    I've been trying to use either of the macros here or here, but am struggling

    I worked out how to get to VB, insert a module and paste the code (having initially kept the /VB tags), but I get the error "Complile Error Syntax Error"

    it is probably something really basic, but I would really appreciate your help.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: first timer using VB to cut and paste macro - getting compile error syntax error

    Paste the actual code you are trying to use on here, in [ code ] tags.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Registered User
    Join Date
    10-24-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: first timer using VB to cut and paste macro - getting compile error syntax error

    thanks OllyXLS, here it is:


    Sub CellColorsToChart()
    Dim oChart As ChartObject
    Dim MySeries As Series
    Dim FormulaSplit As Variant
    Dim SourceRange As Range
    Dim SourceRangeColor As Long
    
    ‘Loop through all charts in the active sheet
    For Each oChart In ActiveSheet.ChartObjects
    
    ‘Loop through all series in the target chart
    For Each MySeries In oChart.Chart.SeriesCollection
    
    ‘Get Source Data Range for the target series
    FormulaSplit = Split(MySeries.Formula, “,”)
    
    ‘Capture the first cell in the source range then trap the color
    Set SourceRange = Range(FormulaSplit(2)).Item(1)
    SourceRangeColor = SourceRange.Interior.Color
    
    On Error Resume Next
    ‘Coloring for Excel 2003
    MySeries.Interior.Color = SourceRangeColor
    MySeries.Border.Color = SourceRangeColor
    MySeries.MarkerBackgroundColorIndex = SourceRangeColor
    MySeries.MarkerForegroundColorIndex = SourceRangeColor
    
    ‘Coloring for Excel 2007 and 2010
    MySeries.MarkerBackgroundColor = SourceRangeColor
    MySeries.MarkerForegroundColor = SourceRangeColor
    MySeries.Format.Line.ForeColor.RGB = SourceRangeColor
    MySeries.Format.Line.BackColor.RGB = SourceRangeColor
    MySeries.Format.Fill.ForeColor.RGB = SourceRangeColor
    
    Next MySeries
    Next oChart
    
    End Sub

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: first timer using VB to cut and paste macro - getting compile error syntax error

    Try replacing the quotation marks in line 15:

    FormulaSplit = Split(MySeries.Formula, “,”)
    as follows:

    FormulaSplit = Split(MySeries.Formula, ",")
    Do you see the very subtle difference?! There's one of the risks of pasting code from a website, which isn't rendered in a plain font. It's why we use [ code ] tags here.

  5. #5
    Registered User
    Join Date
    10-24-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: first timer using VB to cut and paste macro - getting compile error syntax error

    that did get me a little further, I then tried changing
    ‘Loop through all...
    to
    'Loop through all...
    and the other instances of '.

    I now get further, but I have the error runtime error'9': subscript out of range.

    VB highlights this line in yellow:

    Set SourceRange = Range(FormulaSplit(2)).Item(1)
    I wonder if I should define something specific to my workbook? - the webpage implied I could just paste the code and go though?

    thanks, Jo

  6. #6
    Registered User
    Join Date
    10-24-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: first timer using VB to cut and paste macro - getting compile error syntax error

    Solved - not by fixing this, but I found different code that worked (and did what I wanted more closely) - Thanks.


    ... just in-case someone searches using that code, they can find the one which works here.

    It colours charts by the cell colour of the data, so you can easily choose the chart colour and maintain consistency.
    Last edited by jopedder; 10-24-2013 at 11:49 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Compile Error: Syntax Error
    By ndv in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-15-2013, 03:34 AM
  2. [SOLVED] Compile Error : Syntax Error
    By sagar007 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-23-2013, 08:29 AM
  3. [SOLVED] Compile Error: Expected Expression, Syntax Error
    By gjohn282 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-20-2012, 11:28 PM
  4. Compile error: Syntax error
    By ttik in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-24-2011, 09:45 PM
  5. Syntax Error and Compile Error: Expected Line Number or Label...
    By AnthonyWB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-31-2011, 09:59 AM

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