UserForm that updates record on one sheet AND does a search/replace on another?

jmpatrick

Board Regular
Joined
Aug 17, 2016
Messages
230
Office Version
  1. 365
Platform
  1. Windows
Good morning!

I have working code behind a UserForm to update the SubLotCode on a worksheet (called DataCenter). What I need to happen after the SubLotCode is successfully updated is to take that updated information and do a search and replace of all matching instances of the pre-updated SubLotCode on the main sheet (called Calendar). The search and replace will take place in a named range (called SubLotColumn).

Here's my fabulous code:

VBA Code:
Private Sub cmdUpdateSub_Click()
Dim SubName_id As String
SubName = Trim(SubName.Text)
lastrow = Worksheets("DataCenter").Cells(Rows.Count, 5).End(xlUp).Row
For i = 1 To lastrow
If Worksheets("DataCenter").Cells(i, 5).Value = SubName Then
   Worksheets("DataCenter").Cells(i, 2).Value = SubCode.Text
   Worksheets("DataCenter").Cells(i, 4).Value = SubInitials.Text
   Worksheets("DataCenter").Cells(i, 7).Value = FieldManager.Text
End If
Next

        With Me
            .SubName.Clear
            .SubCode.Value = ""
            .SubInitials.Value = ""
            .FieldManager.Clear
        End With
        MsgBox ("Subdivision Successfully Updated!")
        Call UserForm_Initialize

End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

jmpatrick

Board Regular
Joined
Aug 17, 2016
Messages
230
Office Version
  1. 365
Platform
  1. Windows
I just realized that all instances of SubLotCode in my question above should read SubCode.
 

Forum statistics

Threads
1,147,451
Messages
5,741,191
Members
423,647
Latest member
lyanndominique

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top