Home > Software design >  Integrate Replace in a Private Sub
Integrate Replace in a Private Sub

Time:10-28

How to integrate Replace in this Private Sub?

I need to replace all words "NONE" with "":

Private Sub UpdateSKU()

   Dim str As String
   str = Me.Combo216.Column(1) & Space(1) & Me.Combo224.Column(1) & Space(1)
   Me.Text423.Value = str

End Sub

I have tried

Private Function NONE(a As String)
   
   If InStr(a, "NONE") > 0 Then
      MsgBox "Original: " & a & vbCrLf & "Adjusted: " & Replace(a, "NONE", "")
   End If
End Function

But I can't get it to work.

CodePudding user response:

A function should return a value...

Your function does not declare a return type, nor does it ever assign a return value.

Try this instead:

Private Function NONE(a As String) As String
    NONE = Replace(a, "NONE", "")
End Function

CodePudding user response:

Try this:

Private Sub UpdateSKU()

   Dim Text As String
   Text = Me.Combo216.Column(1) & Space(1) & Me.Combo224.Column(1) & Space(1)
   Me.Text423.Value = Replace(Text, "NONE", "")

End Sub

Also, don't use common function names (Str) for variables, and do rename your controls to something meaningful.

  • Related