S
scott
below, I'm finding a cell if it contains string "myword", then i'm trying to
copy (buy I'd rather move the cell 1 cell to the right from where it's
found). I need help on the cell copy (preferably move) part. No matter what
variables I change in the OFFSET part, I can't get the contents in the found
cell to copy (preferably move) 1 cell to the right. My function FINDCELL
works good.
Usage: MoveCell("myword")
Sub MoveCell(ByVal sSearchString As String)
Dim cell As Range
Set cell = FindCell(sSearchString, Sheets(1).Cells)
If cell Is Nothing Then
'action to take of no match
Else
cell(0, -1).Value = cell.Value
End If
End Sub
Function FindCell(searchFor As String, _
searchRange As Range) As Range
Application.DisplayAlerts = False
With searchRange
Set FindCell = .Find(what:=searchFor, After:=.Cells(.Cells.Count), _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
End With
End Function
copy (buy I'd rather move the cell 1 cell to the right from where it's
found). I need help on the cell copy (preferably move) part. No matter what
variables I change in the OFFSET part, I can't get the contents in the found
cell to copy (preferably move) 1 cell to the right. My function FINDCELL
works good.
Usage: MoveCell("myword")
Sub MoveCell(ByVal sSearchString As String)
Dim cell As Range
Set cell = FindCell(sSearchString, Sheets(1).Cells)
If cell Is Nothing Then
'action to take of no match
Else
cell(0, -1).Value = cell.Value
End If
End Sub
Function FindCell(searchFor As String, _
searchRange As Range) As Range
Application.DisplayAlerts = False
With searchRange
Set FindCell = .Find(what:=searchFor, After:=.Cells(.Cells.Count), _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
End With
End Function