I have the below (simplified) example of something I am trying to get vba to do for me in excel. There are 3 columns, the second and third columns may have different titles but basically have the same data. And I would like to keep those two columns.
I would like to find on only the second column certain things and then replace the value on the first column of the row that has the value I am searching for. So as a simple example, I will search only column 2 for all "505" and then replace column 1 of those corresponding rows with "A".
Note, this massive spreadsheet and its data changes everyday, so there is no set number of rows or frequencies of "505". So I will need this to loop. Also, I would need to keep both columns 2 and 3 even though most of the data is repetitive. Can someone help with a simple and robust way of doing this? Thanks in advance!
TYPE ID Model
E 505 505
E 505 505
E 505 505
E 505 505
E 606 606
E 606 606
E 606 606
E 606 606
Code:
Sub searchrange()
'
' searchrange Macro
'
Dim searchrange As Range
Range("A1").Select
Cells.Find(What:="id", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
'this below line is what I am having trouble with; I need to get the (active, or certain) column to be defined as the search range.
searchrange = ActiveCell.EntireColumn.Select
Selection.Find(What:="606", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Selection.Offset(0, -1).FormulaR1C1 = "A"
Cells.FindNext(After:=ActiveCell).Activate
Selection.Offset(0, -1).FormulaR1C1 = "A"
End Sub