Help with simple(?) VBA function

D

Dick Merryman

I'm trying to selectively BOLD cells by the use of a User-Defined function.
No joy.

The VBA Help topics suggest something like this:

Function Bold()
Worksheets("Sheet1").Range("A1:A5").Font.Bold = True
End Function

When I try to use it the referenced cells are not changed and the function
returns "0".

Can anyone point this VBA neophyte in the right direction?

Thanks,

-Dick-
 
F

Frank Kabel

Hi dick
no chance to do this. Functions are not able to change the Excel
environment. E.g. they cannot change other cells or formats. They can
only return values.
 
G

Gord Dibben

Dick

Functions cannot change formatting, only return results.

Try

Sub Bold()
Worksheets("Sheet1").Range("A1:A5").Font.Bold = True
End Sub

Gord Dibben Excel MVP
 
D

Dick Merryman

Guys, thanks for the responses. I did not know that functions were so
limited.

Let me tell you what I am trying to do and maybe you'll have some
suggestions.

I have a spreadsheet that lists manufacturing production options and their
associated costs. What I want to do is select various options by putting an
"x" next to the option and having Excel highlight the option description in
bold and sum the cost into the grand total. I have it all working except
for the bold highlighting.

Any help??

-Dick-
 
D

Dave Peterson

Take a look at Format|conditional formatting...

Say your cells to get bolded are A1:E99 and the X goes into column F of the same
row.
Select A1:E99
and with A1 the activecell,
Format|conditional formatting...

Change it to
formula is
and use this formula:
=$F1="X"

And excel has an =sumif() function that you can use to sum a range if something
else is ok in another range.

Take a look at help for more info.
 
T

Tom Ogilvy

Dim rng as Range, cell as Range
set rng = Range(cells(1,"J"),Cells(rows.count,"A").End(xlup)(1,10))
for each cell in rng
if lcase(cell.value) = "x" then
cell.offset(0,1).Font.bold = True
else
cell.offset(0,1).Font.bold = False
end if
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top