Text Assignment Sometimes Works and Sometimes Doesn't...

Gryfphon

New Member
Joined
Jul 3, 2015
Messages
1
Hi guys

Thank you in advance for taking the time to read this post and trying to help.

Below is a snippet of the code (... indicates code omitted for simplification) where I am trying to annotate a chart after it is generated.

The code sometimes behaves like the Text assignment (last line of code below) is simply a comment and doesn't place the strings into the textbox; when that happens I place a code execution BREAK on the assignment and "Step-Into" the line and it works. Other times it works just fine. Hoping for some possible explanations as to Why?

Code:
 ...

    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.ChartType = xl3DPieExploded
    
         With ActiveChart.Parent
             .Height = 600 ' resize
             .Width = 700  ' resize
             .Top = 5      ' reposition
             .Left = 320   ' reposition
         End With
         
' set range for graph

    If lastRow > 8 Then

        Source = "Graph!" & Range("A2:B10").Address

     Else
        Source = "Graph!" & Range("A2:B8").Address

    End If

    ActiveChart.SetSourceData Source:=Range(Source)
    ActiveChart.HasTitle = False
    ActiveChart.HasTitle = True
    ActiveChart.ChartTitle.Text = "Competitive Range of Hourly Rates"
    ActiveChart.ApplyLayout (1)
    
    ActiveWindow.Visible = True
    Range("A2").Select
    
    ActiveSheet.ChartObjects(1).Activate
    ActiveChart.Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 20.5, 198, 167.25).Select
    
    Sheets(wsName).Select
    
    With ws
    
    
    If lastRow > 8 Then
    
        EvaluateString = "Hourly Rate    Low Pts  Mid Pts " & Chr(10) & _
                  .Cells(2, "A").Value & "              " & .Cells(2, "E").Value & "    " & .Cells(2, "F").Value & Chr(10) & _
                  .Cells(3, "A").Value & "       " & .Cells(3, "E").Value & "    " & .Cells(3, "F").Value & Chr(10) & _
                  .Cells(4, "A").Value & "       " & .Cells(4, "E").Value & "    " & .Cells(4, "F").Value & Chr(10) & _
                  .Cells(5, "A").Value & "       " & .Cells(5, "E").Value & "    " & .Cells(5, "F").Value & Chr(10) & _
                  .Cells(6, "A").Value & "       " & .Cells(6, "E").Value & "    " & .Cells(6, "F").Value & Chr(10) & _
                  .Cells(7, "A").Value & "        " & .Cells(7, "E").Value & "     " & .Cells(7, "F").Value & Chr(10) & _
                  .Cells(8, "A").Value & "        " & .Cells(8, "E").Value & "       " & .Cells(8, "F").Value & Chr(10)


        EvaluateString2 = "" & _
                  .Cells(9, "A").Value & "        " & .Cells(9, "E").Value & "       " & .Cells(9, "F").Value & Chr(10) & _
                  .Cells(10, "A").Value & "           " & .Cells(10, "E").Value & "              " & .Cells(10, "F").Value & Chr(10)

     Else

        EvaluateString = "Hourly Rate    Low Pts  Mid Pts " & Chr(10) & _
              .Cells(2, "A").Value & "              " & .Cells(2, "E").Value & "    " & .Cells(2, "F").Value & Chr(10) & _
              .Cells(3, "A").Value & "       " & .Cells(3, "E").Value & "    " & .Cells(3, "F").Value & Chr(10) & _
              .Cells(4, "A").Value & "       " & .Cells(4, "E").Value & "    " & .Cells(4, "F").Value & Chr(10) & _
              .Cells(5, "A").Value & "       " & .Cells(5, "E").Value & "    " & .Cells(5, "F").Value & Chr(10) & _
              .Cells(6, "A").Value & "        " & .Cells(6, "E").Value & "      " & .Cells(6, "F").Value & Chr(10) & _
              .Cells(7, "A").Value & "        " & .Cells(7, "E").Value & "       " & .Cells(7, "F").Value & Chr(10) & _
              .Cells(8, "A").Value & "        " & .Cells(8, "E").Value & "       " & .Cells(8, "F").Value & Chr(10)
 
        EvaluateString2 = ""
        
    End If
    
    End With
    
    Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = EvaluateString & EvaluateString2

 '''

Thanks again for all your help
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,224,518
Messages
6,179,259
Members
452,901
Latest member
LisaGo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top