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......
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: