Non blank cell

tweek

Board Regular
Joined
Jun 16, 2006
Messages
104
Hi,
How could I write a if statement that say´s something like: IF cell B2 is not blank THEN format a cell like:


Range("IP2").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With

End Sub
 

Some videos you may like

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

gaj104

Well-known Member
Joined
Nov 9, 2002
Messages
864
Hi,

Surely conditional formatting is a better way to achieve this?

Does it have to be done in VBA?
 

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
You could just use conditional formatting...

Highlight cell IP2, click format - conditional formatting
Select "Formula Is"
=B2<>""
Click Format - Borders
Apply border as desired
click OK
click OK


If it must be VB, it would be something like

IF Range("B2").Value <> "" Then
 

tweek

Board Regular
Joined
Jun 16, 2006
Messages
104
Hi, the VB works for me if I write IF Range("B2").Value > "" Then .

I´ll use that since I´ll be doing more complicated things than formatting only.

Thank you very much!!!
 

Watch MrExcel Video

Forum statistics

Threads
1,123,331
Messages
5,601,002
Members
414,419
Latest member
JRDunya

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top