ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Set Range as cells with specific value (https://www.excelbanter.com/excel-discussion-misc-queries/133046-set-range-cells-specific-value.html)

DoooWhat

Set Range as cells with specific value
 
I would like to replace the last section of this code
[SpecialCells(xlCellTypeBlanks)] with something that tells excel to
look for cells with the value "0" in it.

Set rng = .Range(.Cells(2, col), .Cells(LastRow, col)) _
.Cells.SpecialCells(xlCellTypeBlanks)

I am sure this is very simple, just not sure how to do it. As always,
any help is very much appreciated.

Kevin


Dave Peterson

Set Range as cells with specific value
 
Option Explicit
Sub testme()

Dim myRngToSearch As Range
Dim rng As Range
Dim FoundCell As Range
Dim wks As Worksheet
Dim col As Long

Set wks = ActiveSheet
col = 3
With wks
Set myRngToSearch = .Range(.Cells(2, col), _
.Cells(.Rows.Count, col).End(xlUp))
With myRngToSearch
Set FoundCell = .Cells.Find(what:="0", _
after:=.Cells(1), _
LookIn:=xlValues, _
lookat:=xlWhole, _
searchdirection:=xlPrevious, _
MatchCase:=False)
End With
If FoundCell Is Nothing Then
'no 0's
MsgBox "can't finish!"
Else
set rng = .Range(.Cells(2, col), FoundCell)
'rest of code
End If
End With

End Sub


DoooWhat wrote:

I would like to replace the last section of this code
[SpecialCells(xlCellTypeBlanks)] with something that tells excel to
look for cells with the value "0" in it.

Set rng = .Range(.Cells(2, col), .Cells(LastRow, col)) _
.Cells.SpecialCells(xlCellTypeBlanks)

I am sure this is very simple, just not sure how to do it. As always,
any help is very much appreciated.

Kevin


--

Dave Peterson


All times are GMT +1. The time now is 04:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com