I want a macro in Excel to do the following: When ctrl-d is pressed (and some cell X is selected), today's date is inserted into that cell (in form mm/dd/yy).
Press Ctrl+;

Alternatively, if it must be Ctrl+D: ActiveCell.FormulaR1C1 = Date
Thank you. I'm assuming ctrl+; is a pre-built macro then?
Record a macro with the Ctrl+D shortcut then stop without doing anything. Now open the Macro window again, select the macro you just recorded and click Edit. You should see a code editor, into which you can paste the above code, like this:

Code:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 09/12/2011 by Ben Ryves
'
ActiveCell.FormulaR1C1 = Date

'
End Sub
Would the above code put the date in cell (1,1) or the selected cell?
It would put it in the active (i.e. selected) cell. Ctrl+; (and Ctrl+Shift+; for the time) are built-in shortcuts for Excel, not macros per se.
Since you know a lot about VB, perhaps you can help me with this; I have a spreadsheet for attendance. Column A are the names, and the rest are whether or not the person is here. Can I use macros to (assuming the first cell of the old column is selected):
1-insert a new column with the same conditional formatting as the previous row
2- insert today's date (mm/dd/yy)
3- select all the previous columns (from the old to A, not the new one) and set their format to locked
4- lock the sheet with some password
I'm afraid I won't have too much time to look at this in the short term (and am not desperately familiar with Excel) but you should be able to do most of the above by recording a macro, at which point I'm sure someone here can help with any hand tweaking.
I am starting to understand VB, so maybe I just need help with a few parts. Here's the first one. Say I have cell X selected, what would the code be for:
1- the previous range from 2-50
2- the target range from 2-50
That's a good start; if you need specific help with any of the built-in objects, properties or functions then MSDN has a lot of information.
I have given up that Idea for now, but would like these macros.
1- Ctrl+Q protects all columns to right of selected cell
2- Ctrl+w unprotects all
To lock all cells to the right of the currently selected one, something like this should do the trick:


Code:
Range(Columns(ActiveCell.Column + 1), Columns(Columns.Count)).Locked = True


To unlock all cells, something similar could be done:


Code:
Cells.Locked = False
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement