Search/Replace based on user input for one column

willman32

New Member
Joined
Jun 16, 2011
Messages
9
Hey All,

I am trying to make a macro that has a userform that asks the user for todays date. Then apply it to a column and replace all previous dates with the user input (today's date).

Pseudo-code-

if contents in column are less than user input:
replace with user input.


An example is:
A cell in column C has contents : 20110622
User input is 20110623
Replace the cell in column C with user input.

Thanks for looking at this thread

William
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try along the lines of

Code:
Private Sub CommandButton1_Click()
Dim LR As Long, i As Long, x As Variant
LR = Range("C" & Rows.Count).End(xlUp).Row
x = Val(TextBox1.Value)
For i = 1 To LR
    If Range("C" & i).Value < x Then Range("X" & i).Value = x
Next i
End Sub
 
Upvote 0
Hey VoG,

First, thanks for the reply to my thread, your help is greatly appreciated.

I've never used user forms, but I've created a userform and the only thing on it is an input box and a command button. How can I link the two together(code and userform) and run it on a macro, so that the box pops up then the code executes?

Again, thanks for your help.

Regards,

William
 
Upvote 0
OK, right click the button on the userform, select View Code, delete whatever is there and paste in the code that I posted.

Insert > Module then paste in

Code:
Sub Test()
UserForm1.Show
End Sub
Press ALT + Q to close the code window, press ALT + F8, click on Test then click the Run button. Your userform should appear. Enter a date in the text box then click the command button.
 
Upvote 0
Yep it has worked, perfectly I might add.

Just wanted to note, that I was looking for the replace of the data in situ, and the code was posting it in column X. I just simply changed it to C to tailor my needs. It is perfect as is, though, and thank you soooooooo much for your help and time.
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,510
Members
452,918
Latest member
Davion615

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
Back
Top