Results 1 to 8 of 8

Thread: VBA Replace From Code to Range

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    snb
    Guest
    I'd prefer:

    Private Sub CommandButton1_Click()
      sn = Sheet2.Cells(1).CurrentRegion
      With Sheet1
        .TextBox2 = "<MAR>" & .TextBox1 & "</MAR>"    
        For j = 1 To UBound(sn)
          .TextBox2 = Replace(.TextBox2, sn(j, 1), sn(j, 2))
        Next
        .TextBox2 = Replace(Replace(.TextBox2, "#", "; and #"), "; and #", "#", , 1)
      End With
    End Sub
    NB. Put the code in the macromodule it belongs to: sheet1.
    Avoid worksheet interaction (reading / writing) as much as possible: use Arrays (like sn) to do this.
    Last edited by Aussiebear; 04-19-2025 at 10:18 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •