How to assigh certain cells with certain values

Leghorn

New Member
Joined
Sep 7, 2014
Messages
1
Hello everyone. I'm coming here for help to find a solution for a task. I am a hobbyist in excel and usually try to hunt down the answers I need on the net. I have failed. Either by not knowing how to pose the question, or what I want to do is just stupid.
Here is the task. I have made a spread sheet to calculate estimated gross pay on a 2 week pay cycle. Built a 2 week sheet where people could enter their hours worked, rate of pay. Excel pumps out answers. I Put in a clear contents button, to clear the sheet. That's all good, however I would like to make two buttons to set defaults for the two different work shifts at the plant. e.g. shift "A" would push "A Shift" button and the standard hours for that shift would dump in the hours of their standard work cycle. They would then adjust their actual hours worked in the cells to get their estimate. B Shift has a mirror image of hours worked then A Shift.
How do I write a set of instructions in a macro to assign to a button that would then tell the cell "D5" it has the value of "12"
I can clear it by - Range("D5").ClearContents , I can't make it have a value of 12.
If there would be anyone here that can help me with an example of how to write the code for one cell, I could take it from there.
Thanks
Leghorn.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Simple enough. I definitely don't have enough detail, so I tried to make an all encompassing one for you... You will need to make the button and assing this code to it. The button name and the variables will need to be changed appropriately. If you can better describe the setup of your sheet, I can change this as needed.

Code:
Private Sub CommandButton1_Click() ' you will need to change this to the name of the button and put this code on your worksheet, not a module
     Dim hourCol as string' column that stores the hours for shifts
     Dim startRow as integer ' row that shifts start on
     Dim endRow as integer  ' row that shifts end on
     Dim eachRow as integer 'loop helper

     ' change these  values
     hourCol = "D"
     startRow = 5
     endRow = 12

     'Call your clear contents macro here
     ' add shift A
          Range("D5") = 12
          For eachRow = startRow to endRow
               Cell(eachRow, hourCol) = "12:00:00 AM" ' change time
          Next eachRow

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,736
Members
448,988
Latest member
BB_Unlv

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