Start relative reference macro from specific cell

B

Bob K.

This is probably very simple but I can't figure it out. I have button
activated relative reference macros that fill hours worked, total
hours for the day, etc. on time cards. The user selects the first
cell of a particular day (correct cell highlighted in yellow) and then
the button for the shift that he worked that day. Nothing fancy.

The problem is that I don't want the macro to run unless the correct,
yellow-highlighted cell is selected. If the user selects an incorrect
cell and then attempts to run the macro, I want the macro to end
without running and possibly give the user an error message box. The
message box isn't mandatory as long as the macro doesn't run.

I've tried if/then statements based on the active cell but can't get
it to work. Any suggestions?

This is a simplified version of my typical macro; after it fills
cells, the cursor returns to the first cell, which would be my
"starting-point" yellow cell.

ActiveCell.FormulaR1C1 = "'0700"
ActiveCell.Offset (0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "1500"
ActiveCell.Offset (0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 = "8"
ActiveCell.Offset (0, -2).Range("A1").Select
End Sub

Thanks for any help.
 
R

Rob van Gelder

This checks if the currently selected cell is yellow:
If Selection.Interior.Color = vbYellow Then
'...
End If

Keep in mind there are varying shades of yellow. This one is the standard
yellow from the colour palette.


Another approach would be to unlock only the cells you want users to change,
then protect the sheet.

Yet another approach would be to first select the column you want before the
rest of the macro runs.
eg. if you want the cursor to start in column E

Cells(Selection.Row, "E").Select
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top