Results 1 to 3 of 3

Thread: Different errors like statement out of block, variable error showing in my macro

  1. #1
    New Member
    Join Date
    Sep 12
    Posts
    1

    Different errors like statement out of block, variable error showing in my macro

    Hi friends,

    I am new to coding. I was trying to make a macro which searches through the charts in a sheet , searches if the chart has any data of Pfizer and then changing them in the chart to blue. So here, I am trying to search if datalabel has Pfizer and then changing the text to blue.
    I tried using this code but did not work:-
    Code:
    Public Sub chartFormatting()
    
    Dim CTRYname As String
    Dim p As Integer
    ivalue As String
    Dim l As Integer
    Dim rownum As Integer
    
    
    
    For p = 1 To 13
    
    CTRYname = ThisWorkbook.Sheets("Country lookup").Range("A1").Offset(p, 0).Value
     rownum = wkbCurr.Sheets(CTRYname).Range("AA25").End(xlDown).Row
     
     For s = 1 To rownum
     
      ivalue = wkbCurr.Sheets(CTRYname).Charts(1).SeriesCollection(1).Points(s).DataLabel.Text
     
     If InStr(ivalue, "Pfizer") <> 0 Then
     
     With ivalue
     With .Font
     
     .Color = -65536
     .TintAndShade = 0
     End With
     
     End With
     wkbCurr.Sheets(CTRYname).Charts(1).SeriesCollection(1).Points(s).DataLabel.Text = ivalue
     
     
     End If
     
     Next s
     
     Next p
     
    
    
    End Sub
    The variables have been declared else where too.
    Now it is showing me a lot of errors. Please help and suggest a better way of formatting the text and lines in charts.
    My main challenge is to format them only if Pfizer is there.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 02
    Posts
    21,636

    Re: Different errors like statement out of block, variable error showing in my macro

    Since this is a macro, it should be either in the VBA section or the Office Development section... I'll ask a mod to move it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
    *Proof positive that searching the forums does work: View Thread *
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *
    * Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN

  3. #3
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 99
    Location
    Sweden
    Posts
    13,376

    Re: Different errors like statement out of block, variable error showing in my macro

    Moved to the Office Development forum
    Joacim Andersson
    Microsoft MVP, MCSD, MCSE, Sun Certified Java Programmer
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

Posting Permissions

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