 | Junior Member with 22 posts. | | Join Date: Jul 2009 Experience: Beginner | | Solved: Text box border macro based on if text box contains data Text box border macro based on if text box contains data
Hi i have been trying to create some worksheet code so that for a particular sheet if a textbox is blank the border does not show, but if this contains data the border does show. I have the below code, this works if the textbox contains no data but has a border, the code removes the border. However if the text box contains data but has no border the code doesnt draw the border. I am very new to vb so any help gratefully received.
code is:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Sheets("LRCR by division-open").Select
Shapes("Text Box 1").Select
If TextBox1 = "" Then
Selection.ShapeRange.Fill.Visible = msoTrue
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 65
Selection.ShapeRange.Fill.Transparency = 0#
Selection.ShapeRange.Line.Weight = 0.75
Selection.ShapeRange.Line.DashStyle = msoLineSolid
Selection.ShapeRange.Line.Style = msoLineSingle
Selection.ShapeRange.Line.Transparency = 0#
Selection.ShapeRange.Line.Visible = msoFalse
Else
Selection.ShapeRange.Fill.Visible = msoFalse
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.Transparency = 0#
Selection.ShapeRange.Line.Weight = 0.75
Selection.ShapeRange.Line.DashStyle = msoLineSolid
Selection.ShapeRange.Line.Style = msoLineSingle
Selection.ShapeRange.Line.Transparency = 0#
Selection.ShapeRange.Line.Visible = msoTrue
Selection.ShapeRange.Line.ForeColor.SchemeColor = 64
Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
End If
End Sub
thanks | | Distinguished Member with 2,068 posts. | | Join Date: Apr 2006 Location: Down South Experience: Intermediate | | Just a shot here...I'm new to it myself...try adding
Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
in the IF section just before ELSE
Just thinking the two sections should be identical except for the true/falses... and you said you had success with no data...just need it to fill when you enter data which is the IF section if I read it right.
Let me know how it goes...again, I'm very new to this also and still learning.
__________________ Security + | | Distinguished Member with 3,730 posts. | | Join Date: Sep 2003 Location: Atlanta, GA - Planet Earth Experience: Brilliant When Sober | | You need to see if the code under the ELSE statement is even firing. Put a messagebox as the first line after the ELSE and run the code where a border is supposed to be added. If you don't see the messagebox then you know that the code is not even firing.
Regards,
Rollin | | Junior Member with 22 posts. | | Join Date: Jul 2009 Experience: Beginner | | Hi,
Firstly thanks for the responses. I tried adding the line you suggested ckphilli but this didnt work. Rollin_Again i tried adding the message box and you were right, the code after else is not even firing.
The first part of the code works perfectly which is the if text box is blank but has a border remove it. Like i said i am pretty new to this so i thought ok if the second part of the code isnt working then i'll write the code in a different way for the second part, as another IF but this time obviously replacing the "" with <>"". However typing in <>"" into the code causes a compile error: Expected: expression. Any ideas why this is??
Any further help you can provide will be gratefully received.
Thanks | | Distinguished Member with 3,730 posts. | | Join Date: Sep 2003 Location: Atlanta, GA - Planet Earth Experience: Brilliant When Sober | | Can you post your sample workbook and I'll take a look at it.
Regards,
Rollin | | Junior Member with 22 posts. | | Join Date: Jul 2009 Experience: Beginner | | Hi Rollin,
Thanks i will post a copy of that one sheet in about 2 hours...its part of a much bigger overall dashboard so i just need to move it into a standalone workbook or the file size will be too big.
Thank you much appreciated. If you can figure it out let me know what i ahve been doing wrong and i'll make sure i dont do it again!!
Thanks | | Distinguished Member with 3,730 posts. | | Join Date: Sep 2003 Location: Atlanta, GA - Planet Earth Experience: Brilliant When Sober | | In the meantime try including the .Text property of the field in your IF statement. I would also advise to test for the IsEmpty property. If that doesn't work I'll take a look at the posted workbook later today. If TextBox1.Text = "" or IsEmpty(TextBox1.Text) Then
Regards,
Rollin | | Junior Member with 22 posts. | | Join Date: Jul 2009 Experience: Beginner | | Hi Rollin,
Tried your suggestions but these didnt work. The .text solution gave me an object required error. The other solution gave no errors at all but again didnt remove the border if the text box was blank.
I have attached the file but have had to remove the pivot table, can you test this ok using a different trigger for the macro?
Thanks in advance for your help, it just seems to be an issue with the second part of the code. | | Junior Member with 22 posts. | | Join Date: Jul 2009 Experience: Beginner | | File should now be attached, its a 97-02 xls file | | Distinguished Member with 3,730 posts. | | Join Date: Sep 2003 Location: Atlanta, GA - Planet Earth Experience: Brilliant When Sober |
29-Sep-2009, 02:44 PM
#10 | Change your IF statement so that it reads. If ActiveSheet.Shapes("Text Box 1").OLEFormat.Object.Characters.Text = "" Then
Regards,
Rollin | | Junior Member with 22 posts. | | Join Date: Jul 2009 Experience: Beginner |
29-Sep-2009, 03:55 PM
#11 | Rollin,
Works perfectly. I assume that any similar code where i need to select an OLB Object or use it as a variable i need to write the code in the same manner?
Thank you for all your help | | Distinguished Member with 3,730 posts. | | Join Date: Sep 2003 Location: Atlanta, GA - Planet Earth Experience: Brilliant When Sober |
29-Sep-2009, 05:12 PM
#12 | Yes just follow the same format.
Regards,
Rollin |  THIS THREAD HAS EXPIRED.
Are you having the same problem?
We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.
|
Smart Search
| Find your solution! | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |  WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
| You Are Using: |
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 09:08 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd. | |
|