SOLVED

Button to jump and autofill?

Brass Contributor

Is it possible to create a button at A1 that will (1) jump to the first blank cell in that column and (2) fill that cell with today's date (as a value, not a function)?

 

As my first attempt, I created a hyperlink that will go to the first blank cell in that column.  The trouble is that this workbook has 35 sheets (!) and I'd need such a hyperlink on each sheet.  Having that many hyperlinks REALLY consumes memory and slows everything down.

 

So is it possible to do this by putting a macro on a button, by VBA code, or by some other method that doesn't slow everything down to a crawl?

 

Thanks for any help.

7 Replies

Hi @bvelke,

 

You can do that using this code:

Sub JumpToTheFirstBlankCell()
Range("A1").End(xlDown).Activate
ActiveCell.End(xlDown).Offset(1, 0).Select
Selection.Value = Date
End Sub

 

Please check out the attached file.

 

Hope that helps

(Sorry for the delay getting back to you but I've been travelling...)

 

@Haytham Amairah , This is GREAT and I *really* appreciate your help!  It is very nice of you to go to so much trouble to even create 35 tabs for testing.

 

Unfortunately, while your sample workbook works great, your button doesn't work on mine (small sample attached).  A button click always goes to A6.  I want it to go to A45 in this case, of course.  (I would understand if it went to A2 or A4 and I'd find a work-around for that - like putting a dummy value in those cells).

 

There must be something about the values/format of my cells which is breaking your code but I can't figure what that might be.

 

Thanks again for your expert help!

best response confirmed by bvelke (Brass Contributor)
Solution

@bvelke

 

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 Sub

Screenshot_1.png

 

Hope 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.

@bvelke

 

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

@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.

@bvelke

 

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.

1 best response

Accepted Solutions
best response confirmed by bvelke (Brass Contributor)
Solution

@bvelke

 

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 Sub

Screenshot_1.png

 

Hope that helps

View solution in original post