Excellearner
New Member
- Joined
- Jan 13, 2005
- Messages
- 7
Hi All,
I am still New Bee and trying to learn VBA concepts.Quick help is really appreciated.
I am trying to select a row based on the searchstring and search for strings "X", "F" and "P" and replace them with either "P" or "F" based on User form entries.
Following is the code and i also tried .Find. Please help
ray:
Private Sub cmdStatus_Click()
Dim rng1 As Range
Dim NewAddress As String
Dim Exstring As String
Dim Rownumber As Integer
Dim StringLength As Integer
Dim TestStatus As Boolean
Dim LastCellAddress
SearchString = txtTestCase.Value
With ActiveSheet.Cells
Set c = .Find(SearchString, LookIn:=xlValues)
If Not c Is Nothing Then
NewAddress = c.Address(RowAbsolute:=False, ColumnAbsolute:=False)
Rownumber = Right(NewAddress, 1) 'Finding the Row Number of the Test Case
StringLength = Len(NewAddress)
If IsNumeric(Mid(NewAddress, 2, 1)) Then
Rownumber = Right(NewAddress, StringLength - 1)
Else
Rownumber = Right(NewAddress, StringLength - 2)
End If
Set rng1 = ActiveSheet.Rows(Rownumber) 'Selecting the row of the entered Test Case
'Seeting Test Status to Pass or Fail
If optPass.Value = True Then
TestStatus = "P"
ElseIf optPass.Value = False Then
TestStatus = "F"
End If
Dim Lookc As Range
'Rows(rng1.Address).Select
'Range(rng1.Address).Select
Selection.Replace What:="X", Replacement:=TestStatus, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Selection.Replace What:="P", Replacement:=TestStatus, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Selection.Replace What:="F", Replacement:=TestStatus, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
txtTestCase.SetFocus
txtTestCase.Value = ""
txtTestCase.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
Else
MsgBox "Test Case :" & SearchString & " could not be found "
txtTestCase.SetFocus
txtTestCase.Value = ""
txtTestCase.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
End If
End With
End Sub
I am still New Bee and trying to learn VBA concepts.Quick help is really appreciated.
I am trying to select a row based on the searchstring and search for strings "X", "F" and "P" and replace them with either "P" or "F" based on User form entries.
Following is the code and i also tried .Find. Please help
Private Sub cmdStatus_Click()
Dim rng1 As Range
Dim NewAddress As String
Dim Exstring As String
Dim Rownumber As Integer
Dim StringLength As Integer
Dim TestStatus As Boolean
Dim LastCellAddress
SearchString = txtTestCase.Value
With ActiveSheet.Cells
Set c = .Find(SearchString, LookIn:=xlValues)
If Not c Is Nothing Then
NewAddress = c.Address(RowAbsolute:=False, ColumnAbsolute:=False)
Rownumber = Right(NewAddress, 1) 'Finding the Row Number of the Test Case
StringLength = Len(NewAddress)
If IsNumeric(Mid(NewAddress, 2, 1)) Then
Rownumber = Right(NewAddress, StringLength - 1)
Else
Rownumber = Right(NewAddress, StringLength - 2)
End If
Set rng1 = ActiveSheet.Rows(Rownumber) 'Selecting the row of the entered Test Case
'Seeting Test Status to Pass or Fail
If optPass.Value = True Then
TestStatus = "P"
ElseIf optPass.Value = False Then
TestStatus = "F"
End If
Dim Lookc As Range
'Rows(rng1.Address).Select
'Range(rng1.Address).Select
Selection.Replace What:="X", Replacement:=TestStatus, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Selection.Replace What:="P", Replacement:=TestStatus, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Selection.Replace What:="F", Replacement:=TestStatus, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
txtTestCase.SetFocus
txtTestCase.Value = ""
txtTestCase.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
Else
MsgBox "Test Case :" & SearchString & " could not be found "
txtTestCase.SetFocus
txtTestCase.Value = ""
txtTestCase.EnterFieldBehavior = fmEnterFieldBehaviorRecallSelection
End If
End With
End Sub