what's wrong with this IF statement?

iknowu99

Well-known Member
Joined
Dec 26, 2004
Messages
1,158
Code:
If Application.Cells(wsFr.Cells(Rows.Count, iSourceCol).End(xlUp).Row, iSourceCol).Font.Bold = False And Application.Cells(wsFr.Cells(Rows.Count, iSourceCol).End(xlUp).Row, iSourceCol).Font.ColorIndex <> 3 Then

thanks
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Not sure if the coding for 'bold' and 'red' are referred to appropriately

yaikes :eek:
 
Upvote 0
Hi,

did you try to parse your code into parts ??
why not try code like
If Range("A1").Font.Bold = True Then MsgBox "yes"
If Range("A1").Font.Bold Then MsgBox "yes"
or
MsgBox Range("A1").Font.Bold

... OK this works
... next part

MsgBox Application.Range("A1").Font.ColorIndex

OK :)

does the cell exist ?
Code:
Cells(wsFr.Cells(Rows.Count, iSourceCol).End(xlUp).Row, iSourceCol).Select

etcetera
why did you put Application before Cells ?
I assume wsFr is a sheetname ?

doing further tests
as I do not have more code I've made my own variable values
Code:
Dim wsFr As Worksheet
Const iSourceCol = 5
Set wsFr = Sheets(2)
MsgBox Application.Cells(wsFr.Cells(Rows.Count, iSourceCol).End(xlUp).Row, iSourceCol).Font.Bold
MsgBox Application.Cells(wsFr.Cells(Rows.Count, iSourceCol).End(xlUp).Row, iSourceCol).Font.ColorIndex <> 3
still working regardless what the activesheet is
works in sheetmodule

next step
Code:
Dim wsFr As Worksheet
Const iSourceCol = 5
Set wsFr = Sheets(2)
If Application.Cells(wsFr.Cells(Rows.Count, iSourceCol).End(xlUp).Row, iSourceCol).Font.Bold = False And Application.Cells(wsFr.Cells(Rows.Count, iSourceCol).End(xlUp).Row, iSourceCol).Font.ColorIndex <> 3 Then MsgBox "hello"
shouldn't have done all those steps, since this still works ... but those steps served to show you a way how to proceed

conclusion
I cannot reproduce the error, so my guess is the variables are not properly set
what do you get with this code
(instead of the Messageboxes you could use the Locals window in VB-Editor while stepping through the code using function key F8
Code:
MsgBox iSourceCol
MsgBox wsFr.Name
errors ?

kind regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,214,829
Messages
6,121,827
Members
449,051
Latest member
excelquestion515

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
Back
Top