Macro for input box to replace formula cells with 0

dnasim

New Member
Joined
Jul 11, 2014
Messages
16
Hello I have this worksheet.

Sample Data from "Demand Planning Prem" worksheet

DateSKUNameBegin FG'sAdd ReturnsDemand FGEnd FG'sWeeks FGExcess FG
6/20/2014ASDRK-301Tent57181585661985339
6/27/2014ASDRK-301Tent566173656321565310
7/4/2014ASDRK-301Tent563243855981475276
7/11/2014ASDRK-301Tent559873855601465238
7/18/2014ASDRK-301Tent556053855221455200
8/1/2014ASDRK-301Tent552223854841445162
8/1/2014ASDRK-301Canoe548473854461435124
8/8/2014ASDRK-301Canoe544693854081425086

<tbody>
</tbody>

This worksheet has around 40,000 records, and I need to create a Macro that will ask the user for a date, and when the user enters a date the macro goes through column A and finds all of the matching dates and then replaces the numbers (along with the formulas) in the corresponding Add Returns cells (column E) with 0's.

I have only been able to create an inputbox, but I am completely lost regarding the criteria due to being very new to VBA.

Sub ClearData()
Dim EnterDate As Date
Dim msg As String
msg = "Please enter a date in the mm/dd/yyyy format"
EnterDate = Inputbox(msg)
ActiveSheet.Range("A")

If EnterDate = Range("A") Then
Range("E") = 0
End if
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi There


Try this

Code:
Sub ClearData()
Dim EnterDate As Date
Dim msg As String
Dim i As Range

Lrow = Sheets("[COLOR=#00ff00]Sheet1[/COLOR]").Cells(Rows.Count, "A").End(xlUp).Row
msg = "Please enter a date in the mm/dd/yyyy format"
EnterDate = InputBox(msg)

For Each i In Range("A1:A" & Lrow)

If EnterDate = i.Value Then
i.Offset(0, 4).Value = 0
End If

Next i

End Sub

Don't forget to modify
Code:
"Sheet1"
to reflect the name of your sheet. If you want it to run in the selected shhet change
Code:
Sheets("sheet1")
for
Code:
ActiveSheet

try this code in a copy of your workbook first
 
Upvote 0

Forum statistics

Threads
1,215,409
Messages
6,124,743
Members
449,186
Latest member
HBryant

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