spreadsheet object

G2K

Active Member
Joined
May 29, 2009
Messages
355
Hi All,

i have a Spreadsheet objedct on Excel vba form. i want to format the cells based on certain criteria. below is the code -


Spreadsheet1.Range("C2:C" & Spreadsheet1.Cells(Spreadsheet1.Rows.Count, 1).End(xlUp).Row).Select
Spreadsheet1.Range(Spreadsheet1.Selection, Spreadsheet1.Selection.End(xlToRight)).Select

For Each cell In Spreadsheet1.Selection ' --generates type mismatch error here

If cell.Value <> "P" Then cell.Interior.ColorIndex = 3

Next cell

alternatively i tried this--

Spreadsheet1.Range("C2:C" & Spreadsheet1.Cells(Spreadsheet1.Rows.Count, 1).End(xlUp).Row).Select
cCount = Spreadsheet1.Selection.Rows.Count
Spreadsheet1.Range(Spreadsheet1.Selection, Spreadsheet1.Selection.End(xlToRight)).Select
rCount = Spreadsheet1.Selection.Columns.Count

For i = 1 To rCount

For j = 1 To cCount

Spreadsheet1.Selection(j).Activate
If Spreadsheet1.Selection(j) = "P" Then Spreadsheet1.Selection(j).Interior.ColorIndex = 3
Next j

Next i

this code runs succesfully but it works for first row only. i do not know how to increment row number in selection, also it works very slow.

Can anybody help.............

Thanks in advance......
 
Last edited:
i got the solution and would like to say sorry to you all for this follish question-

Spreadsheet1.Range("C2:C" & Spreadsheet1.Cells(Spreadsheet1.Rows.Count, 1).End(xlUp).Row).Select
cCount = Spreadsheet1.Selection.Rows.Count
Spreadsheet1.Range(Spreadsheet1.Selection, Spreadsheet1.Selection.End(xlToRight)).Select
rCount = Spreadsheet1.Selection.Columns.Count

For i = 1 To cCount

For j = 1 To rCount

Spreadsheet1.Selection.Cells(i, j).Activate
If Spreadsheet1.Selection.Cells(i, j) = "P" Then Spreadsheet1.Selection.Cells(i, j).Interior.ColorIndex = 3
Next j

Next i

can anybody tell me why for ecah is not working here
 
Upvote 0

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