[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Formatting a text string created in Excel to include subscripts

Posted on 2011-03-03
7
Medium Priority
?
359 Views
Last Modified: 2012-05-11
Some values generated with VBA code are used in a spreadsheet to produce a text string that is then used on a graph of the code's output as a data label marker

The text string is ="P"&TEXT(N15*100,"##")&"=$"&TEXT(N16,"#0.0")&"M" where the contents of the cells N15 and N16 are part of the code output

I want the two digits following the letter P to be subscripts to the P

Can I achieve this with formatting in Excel or can I create the same string in VBA with the subscript formatting so I could just write it to the label cell in the spreadsheet?

I know I can do it manually for static data but this has to be linked to the output of the code and update automatically
0
Comment
Question by:sjgrey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 39

Expert Comment

by:nutsch
ID: 35032769
Try this

[a1] = "P" & Format([n15] * 100, "##") & "=$" & Format([n16], "#0.0") & "M"
[a1].Characters(Start:=1, Length:=2).Font.Subscript = True

Thomas
0
 
LVL 39

Accepted Solution

by:
nutsch earned 2000 total points
ID: 35032776
Actually, start:=2 not 1

[a1] = "P" & Format([n15] * 100, "##") & "=$" & Format([n16], "#0.0") & "M"
[a1].Characters(Start:=2, Length:=2).Font.Subscript = True

Thomas
0
 
LVL 1

Author Comment

by:sjgrey
ID: 35033128
Thanks for the swift response

Could you just clarify the notation for me please?  Does [a1] mean a VBA reference to the cell where the string is to wind up?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 39

Expert Comment

by:nutsch
ID: 35033186
Exactly, that notation could also be put

cells(row,column)
                          cells(1,1)

range("address")
                         range("A1")

So what I've given you is the code to put the result in cell A1. Do you need assistance in putting that in a macro / workbook?

T
0
 
LVL 1

Author Comment

by:sjgrey
ID: 35033294
I think I get it.  My code looks like this.

    
    Worksheets("Graph").Activate
    Cells(3, 2).Value = "P" & Format([n15] * 100, "##") & "=$" & Format([n16], "#0.0") & "M"
    Cells(3, 2).Characters(Start:=2, Length:=2).Font.Subscript = True

Open in new window


The only problem I now have is that, even with the following code to force the graph to update after calculating the data points it displays, the label that refers to the cell B3 or Cells(3,2) doesn't update.  It just shows the value it had when the reference was initially set up in the Select Data dialog.

    Application.Calculation = xlCalculationAutomatic
    Worksheets("Graph").Activate
    Application.Calculate
    

Open in new window


Changes in the numbers driving the graph are picked up.  The lines it draws are moved around when the inputs change, but the label on a data point used to label a marker on the graph is stuck. Labelling-bug.docx

The vertical line on the graph is in the right place as is a single point, which has no marker, that I place above the top of the line.  The label is attached to the single point but it isn't changing even though the contents of the cell it refers to have changed.  The subscripting worked perfectly thanks.

Any ideas on the label update?

I'm happy to start a fresh question if that would be more appropriate.
0
 
LVL 39

Expert Comment

by:nutsch
ID: 35037960
The label is hardcoded in the cell, which means it's no longer a formula and will only update when you run that macro. What you can do is put it in a worksheet_change macro so it will run every time a cell changes on that sheet.

Do you want help doing this or do you just want to rerun the macro each time?

Thomas
0
 
LVL 1

Author Comment

by:sjgrey
ID: 35040680
If there is an easy way to make the label pdate when the cell changes I'd be very interested and I don't know how to do that yet
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question