Wow, I finally got through my first VB "tutorial" project and everything works nice, except one userform label caption will only display as long as the Excel column it draws data from is set wide enough to show the data on the spreadsheet too. But that data is not supposed to be visible to spreadsheet users, as it involves intermediate calculations only. I don't see anything special about either that particular data (it's numeric) or about the coding, but here it is, in case you can spot something there. - Label4.Caption = Label4.Caption + Worksheets("Next Service").Range("I51").Text & " mi" & Chr(13)
Otherwise, are there any suggestions you can offer me? Oh, and if I set the column width to some small width, both the data cell and the userform label caption show ###. I know why excel displays that, but not why it would be rendered that way in the VBA project or what to do about it. TIA
Annie
4 5081
I agree that is should work, but it is always shakey to use range.Text because it returns what shows on the worksheet, but I didn't know that hidden cells have blank .Text. Use .Value instead and let VB convert it to a string. HTH --Sam
Hi Sammy. Thanks for the response. Using .Value in place of .Text leads to a "Type Mismatch" run-time error. Anyway, the label caption will render all of the desired worksheet cell contents correctly, but only if the worksheet data column is wide enough to display it too, and that's what I don't want to have to do. The user has no interest in that data and so shouldn't even be seeing it on the worksheet. And yet, when I set the column width to 0 on the worksheet to hide it there, it's hidden in the userform label caption too! I hope someone has come across this odd situation and has already figure it out. I'll keep working on it too, but when it comes to VB, I don't yet have a very big tool chest to reach into. Ha ha.
Annie
Novice VBA mistake (I've already made a ton of those). I'm posting the solution for anyone facing a similar problem in the future who comes across this thread.
Sam was on the right track to use .Value in place of .Text, but I kept getting the "Type mismatch" error. Eventually, it was pointed out to me that my coding line was using a "+" to join two parts of the label together, rather than the "&". Not only did "&" and ".Value" together take care of the type mismatch error, but the caption now renders correctly and displays, even with the worksheet column width set to 0. Annie is happy now. Thanks.
Annie
agree with annie and Sammy:
When working with strings, or not, always use & instead of +, just to avoid mistakes.
Instead of using Range and the cell's name, use the Cells index, e.g. instead of Range("I51"), i'll rather use Cells(51,8).
And yes, Value is a property that is always there.
And instead of CHR(13), use the VB constant for new line (that combines CHR(13) and CHR(10)): vbNewLine
So perhaps this will do:
Label4.Caption = Label4.Caption & Worksheets("Next Service").Cells(51,8).Value & " mi" & vbNewLine
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Wally |
last post by:
I would like to have an image with a caption displayed below it. The
size of the image will vary. The caption should not extend beyond the
width of the image.
How can I cause the text of the...
|
by: Jared |
last post by:
Here is my situation. I have multiple labels on a form but only
certain ones will become visible while using the form. Depending on
which check box(s) you pick, on another form, determines the...
|
by: rn5a |
last post by:
Consider the following code:
<script runat="server">
Sub ShowData(obj As Object, ea As EventArgs)
lblDate.Text = DateTime.Now.ToString("d")
lblDate.DataBind()
End Sub
</script>
<form...
|
by: dgardner |
last post by:
This one has me stumped and I hope someone can help.
I have a form with a button on it. When I click the button, I want a
label named lblWait to be visible. (When the form opens, the label is...
|
by: Chris Beall |
last post by:
See
http://pages.prodigy.net/chris_beall/Demo/photo%20block%20experiments.html
I've ended up with what seems like a rather complex structure for what I
thought would be a somewhat simple...
|
by: Peter Parker |
last post by:
Could someone show me how to limit caption width to image width dynamically
(image width is not known in advance) if that's possible? I was thinking of
using Javascript to get the image width which...
|
by: bruce628 |
last post by:
I want to use SWT Label and popmenu to construct a menubar ,and the effect
of this menubar is same to the menubar in SWT.When click the Label,it should be highlighted and popmenu shows.The issue is...
|
by: daJunkCollector |
last post by:
I am trying to display a column from a database table in the column of a datagrid. I am using a template column to display it.
There are two things that are important to me:
1. If...
|
by: Kevin McKinley |
last post by:
Below i've put the code for a program that i wrote. I need help on lines 384-403. If you run this program you will notice on the first tab when have it produce an answer the $ is surrounded with...
|
by: Guilherme Polo |
last post by:
On Wed, Sep 3, 2008 at 8:57 PM, Kevin McKinley <kem1723@yahoo.comwrote:
Come on.. "help on lines 384-403", that is not a good way to look for
help. You are supposed to post some minimal code that...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |