[PA] 업무자동화/[XL]Excel & VBA
XL Range.Find method
Weneedu
2021. 2. 11. 23:23
20210211 0920
Ref
[1] "docs.microsoft.com/en-us/office/vba/api/excel.range.find"
Syntax
expression.Find (What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SearchFormat)
expression A variable that represents a Range object.
① Range가 찾는 범위
② Range에 찾는 항목이 여러 개 있다면?
exampe [1]
This example finds all cells in the range A1:A500 in worksheet one that contain the value 2, and changes the entire cell value to 5. That is, the values 1234 and 99299 both contain 2 and both cell values will become 5.
Sub FindValue()
Dim c As Range
Dim firstAddress As String
With Worksheets(1).Range("A1:A500")
Set c = .Find(2, lookin:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = 5
Set c = .FindNext(c)
Loop While Not c Is Nothing
End If
End With
End Sub