Mourning the loss of our friend, WhitPhil.
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Business Applications
Tag Cloud
access audio blue screen boot bsod connection crash dell desktop driver drivers dvd email error excel excel 2003 firefox hard drive hardware hijackthis internet keyboard laptop malware monitor motherboard network networking outlook problem processor recovery router screen slow sound spyware tdlwsp.dll trojan upgrade vba video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Business Applications >
Solved: Text box border macro based on if text box contains data

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
ashleywanless's Avatar
Computer Specs
Junior Member with 22 posts.
 
Join Date: Jul 2009
Experience: Beginner
26-Sep-2009, 07:32 AM #1
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
ckphilli's Avatar
Distinguished Member with 2,068 posts.
 
Join Date: Apr 2006
Location: Down South
Experience: Intermediate
28-Sep-2009, 12:59 AM #2
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 +
Rollin_Again's Avatar
Distinguished Member with 3,730 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
28-Sep-2009, 07:15 AM #3
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
ashleywanless's Avatar
Computer Specs
Junior Member with 22 posts.
 
Join Date: Jul 2009
Experience: Beginner
29-Sep-2009, 09:55 AM #4
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
Rollin_Again's Avatar
Distinguished Member with 3,730 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
29-Sep-2009, 09:59 AM #5
Can you post your sample workbook and I'll take a look at it.

Regards,
Rollin
ashleywanless's Avatar
Computer Specs
Junior Member with 22 posts.
 
Join Date: Jul 2009
Experience: Beginner
29-Sep-2009, 10:21 AM #6
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
Rollin_Again's Avatar
Distinguished Member with 3,730 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
29-Sep-2009, 11:09 AM #7
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
ashleywanless's Avatar
Computer Specs
Junior Member with 22 posts.
 
Join Date: Jul 2009
Experience: Beginner
29-Sep-2009, 12:40 PM #8
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.
ashleywanless's Avatar
Computer Specs
Junior Member with 22 posts.
 
Join Date: Jul 2009
Experience: Beginner
29-Sep-2009, 12:44 PM #9
File should now be attached, its a 97-02 xls file
Attached Files
File Type: xls Book1.xls (52.0 KB, 19 views)
Rollin_Again's Avatar
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
ashleywanless's Avatar
Computer Specs
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
Rollin_Again's Avatar
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
Closed Thread Bookmark and Share

Tags
excel, macros, vba

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.

Thread Tools


You Are Using:
Server ID
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.
Powered by Cermak Technologies, Inc.