Forum Discussion
Button to jump and autofill?
- Jun 01, 2019
The solution is to make the starting cell in the macro always the first left-most cell in the table which is A5.
Which require changing the code a little bit as follows:
Sub JumpToTheFirstBlankCell()
Range("A5").End(xlDown).Offset(1, 0).Select
Selection.Value = Date
End SubHope that helps
That works great, thanks again!
I notice that you combined your first two lines of code. I'm still not sure how they work but you've inspired me to buy a book on VBA because it seems that it will open up a whole new world of possibilities for my workbooks. I might even figure out how to add a Tab (to move to the next column) at the end of your macro. :-)
Again, I very much appreciate your help.
The code is very simple!
Range("A5").End(xlDown).Offset(1, 0).Select
I used Range("A5") to start with range A5, then used End(xlDown) to move down to the last filled cell in the range as if you were pressing the keyboard shortcut (Ctrl+Down Arrow).
The last portion of the line Offset(1, 0).Select used to move down one row to the first blank cell and select that cell.
If you want to move to the next column change it as follows: Offset(1, 1).Select.
I think the second line is clear!
Selection.Value = Date
It sets the value of the selected cell to the current date, where Date is the VBA equivalent to the worksheet function TODAY().
Hope that helps
- bvelkeJun 01, 2019Brass Contributor
Haytham Amairah Actually, I wanted it to fill in the date using your code and then move one column to the right. So I added this at the end of your code:
ActiveCell.Offset(0, 1).Range("A1").Select
I confess that I cheated. I recorded a macro and then looked at the code that it generated. :-) But now I have exactly what I wanted!
Thanks again for all of your help.
- Haytham AmairahJun 01, 2019Silver Contributor
You're welcome.
By the way, this is common practice, I also do it sometimes.
I confess that I cheated. I recorded a macro and then looked at the code that it generated.