

July 7, 2016

Hello,
This one should be simple, but I don't know the structure. I have a bit of code:
SHAPENAME = "Textbox 262"
inputtext = ['Pt Volume'!FW461]
With Me.Shapes(SHAPENAME).TextEffect
.Text = inputtext
.FontBold = msoTrue
.FontSize = 16
End With
i = 1
With Me.Shapes(SHAPENAME).TextFrame.Characters(i, 1).Font
.Size = 18
End With
startofword = False
For i = 2 To Len(inputtext)
If ((startofword) And (Mid(inputtext, i, 1) <> " ")) Then
startofword = False
With Me.Shapes(SHAPENAME).TextFrame.Characters(i, 1).Font
.Size = 18
End With
End If
If Mid(inputtext, i, 1) = " " Then startofword = True
Next
This code capitalizes a text string inserted in a textbox, like so: ='Pt Volume'!FW461. Works fine, but if I insert a row or column, FW461 doesn't adjust for the new cell location. So, I named cell 'Pt Volume'!FW461, TextboxLabel1, and changed the line above to inputtext = Range("TextboxLabel1"). But it didn't work. The syntax must be wrong. What is the correction needed?
Paul

VIP

Trusted Members

June 25, 2016



July 7, 2016

The actual file is gigantic and creating a sample from it could be a problem. Let me explain: I have labels in some parts of the file that are used as formulas in textboxes. These display just fine but Excel has no smallcaps function like in Word. The code above creates the smallcaps look by locating the first letter of a word in that formula to 18pt font, and the rest in 16pt. For example, ='Pt Volume'!FW461 refers to this text string: OUTPATIENT VISITS. The code will increase the font size of O and V. So far, so good.
The problem with code referring to cell addresses is that the code doesn't update when the cell address changes. If the code refers to Range("D10"), for example, and I move D10 to E10, the code won't automatically change to Range("E10"). But if I name D10 TextboxLabel1, inserting it as code like this--Range("TextboxLabel1"), it does. But I've got the syntax wrong. Leave out the Range and parentheses, like this, maybe? inputtext = "TextboxLabel1"

VIP

Trusted Members

June 25, 2016



July 7, 2016

Hi Sunny,
I won't be typing a label into the cell, however. The label is a row header generated by an IF statement, such as, if "Inpatients" is selected in the settings data validation dropdown list, then the formula generates a label of "U.S. INPATIENT POPULATION," for example. The code above takes that uppercase label and formats it in smallcaps style like in MS Word. If the labels didn't change, I could just enter it the way I want in the textbox and leave it at that, and I have a bunch of those, but this code I'm writing about is for the exceptions. And it works great, too.
The problem is, I want to replace this line
inputtext = ['Pt Volume'!FW461]
with this line
inputtext = Range("TextboxLabel1")
where TextboxLabel1 is the range name for cell 'Pt Volume'!FW461, but the syntax must be wrong. Excel stops when it encounters that line.
Paul

VIP

Trusted Members

June 25, 2016


VIP

Trusted Members

June 25, 2016

Hi Paul
I think you cannot format a formula in a textbox.
This is what I came up with. Not elegant (never done this before) but should work.
I have named the cell containing the text so that it is dynamic.
What the code does is to add the required text to the textbox and then format it.
I don't know if you textbox will be auto update when the cell change or you trigger it by clicking a button.
I chose to add a button in this example.
You will need to modify it to suit your needs.
Hope this helps.
Sunny


July 7, 2016

You're right, you can't format the formula, but somehow, my textboxes are formatted anyway. I didn't write the code, only adapted it. Yours here seems to do much the same thing. I'll see if I can adapt this to my situation and let you know what happens. Many thanks, once again.
Paul
1 Guest(s)
