Unable to set the bold property of the font class

I

Izran

I cannot seem to figure out how to make a cells contents bold when
referencing them with the cells function. I keep getting unable to set
hte bold property of the font class.


Specific Section of code:


iRowCountTo = iRowCountTo + 1
Sh2.Cells(iRowCountTo, 1).Value = _
Sh1.Cells(iRowCountFrom, 2).Value
Sh2.Cells(iRowCountTo, 1).Cells.Font.Bold = True
Sh2.Cells(iRowCountTo, 3).Value = _
Sh1.Cells(iRowCountFrom, 3).Value
Sh2.Cells(iRowCountTo, 3).Cells.Font.Bold = True




The Whole Subroutine:


Sub Air_Commodity_View()


Dim Sh1 As Worksheet
Dim Sh2 As Worksheet
Dim Sh3 As Worksheet


Dim iRowCountFrom As Integer, iColCountFrom As Integer
Dim iRowCountTo As Integer, iColCountTo As Integer
Dim iColumnCountMMM As Integer


Dim rFromCell As Range
Dim rToCell As Range
Dim rLookupTable As Range
Dim iListMax As Integer


iRowCountTo = 9
iRowCountFrom = 4
iColumnCountTo = 2
iColumnCountFrom = 2


Set Sh1 = Sheets("Air_List")
Set Sh2 = Sheets("Commodity_Entry")
Set Sh3 = Sheets("MMM Index")


Set rLookupTable = Sh3.Range("MMM_TABLE")


Sh2.Range("A10:C65536") = Empty


iListMax = Sheets("Air_List").Range("A1")
For iRowCountFrom = 4 To iListMax + 3
If Not IsEmpty(Sh1.Cells(iRowCountFrom, 2).Value) Then
iRowCountTo = iRowCountTo + 1
Sh2.Cells(iRowCountTo, 1).Value = _
Sh1.Cells(iRowCountFrom, 2).Value
Sh2.Cells(iRowCountTo, 1).Cells.Font.Bold = True
Sh2.Cells(iRowCountTo, 3).Value = _
Sh1.Cells(iRowCountFrom, 3).Value
Sh2.Cells(iRowCountTo, 3).Cells.Font.Bold = True


For iColCountMMM = 4 To 31
If Not IsEmpty(Sh1.Cells(iRowCountFrom, _
iColCountMMM).Value) Then
iRowCountTo = iRowCountTo + 1
Sh2.Cells(iRowCountTo, 2).Value = _
Sh1.Cells(iRowCountFrom, iColCountMMM).Value
Sh2.Cells(iRowCountTo, 3).Value = _
Application.VLookup(Sh1.Cells(iRowCountFrom,
iColCountMMM).Value, rLookupTable, 2, False)
End If
Next iColCountMMM
End If


iRowCountTo = iRowCountTo + 1


Next iRowCountFrom


End Sub



Regards,
MPManzi
 
C

Chip Pearson

Is Sh2 protected?

I thought of that, too. But the line of code above the Bold line
puts a value on Sh2, so I assumed that the sheet was not
protected.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
I

Izran

Something else perculiar: WHen I set a watch on Sh2.Cells(iRowCountTo,
1) or the like, and I try to expand it in the watch box to its
subdirectories, when I try to expand cells Excel crashes. Wondering if
that has something to do with it - the program can't access the .cells
subdirectory udner the object??????
 
B

Bernie Deitrick

Izran,

While I wasn't able to reproduce your crash, you could try changing

Sh2.Cells(iRowCountTo, 1).Cells.Font.Bold = True

to

Sh2.Cells(iRowCountTo, 1).Font.Bold = True

HTH,
Bernie
MS Excel MVP
 
I

Izran

That did the trick!!! Was hung up on that for awhile, but fortunately
I had other aspects to work on for the application. TYVM!!

Regards,
MPManzi
 

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