Back Forum Reply New

Select the next cell Down or up

I want to use a macro to select the next cell down under a set of data.
however if I record it as a macro with the combination
ctrl + Down, Down
the macro is recored as

Code:
Selection.End(xlDown).Select   Range("A24").Select
obviously the A24 bit forces it to select that cell no matter where it was before.
Whats the correct code to replace this with?

TryCode:
Selection.End(xlDown).Offset(1, 0).Select
But why do you need to Select?

Perhaps I don't - I'm new to VBA and have tried to record the macro and edit it.
I am trying to add titles to the top of groups of data and a total to the bottom of another.
so I will end up with

Code:   Selection.End(xlDown).Select   Selection.End(xlDown).Offset(-1, 0).Select   Selection.Font.Bold = True   ActiveCell.FormulaR1C1 = "Order Backlog"
This works but it quite long winded - is there a better way?

Perhaps something like thisCode:
With ActiveCell.End(xlDown).Offset(1, 0)   .Font.Bold = True   .Value = "Order Backlog"
End With
but you shouldn't even need to use ActiveCell. Perhaps if you could post a small sample of your data using Excel Jeanie index.php?f=1 it would be clearer what you are trying to do.

please see this thread for details
forum/showthread.php?t=331141
I have it working now - but how effiecient is it??

Code:
Sub Titles()      Range("A2").Select   Selection.Font.Bold = True   ActiveCell.FormulaR1C1 = "Despatched Orders"         Selection.End(xlDown).Offset(1, 0).Select   Selection.Font.Bold = True   ActiveCell.FormulaR1C1 = "Order Backlog"       Selection.End(xlDown).Offset(1, 0).Select   Selection.Font.Bold = True   ActiveCell.FormulaR1C1 = "New Orders"      Selection.End(xlDown).Select   Selection.End(xlDown).Offset(-1, 0).Select   Selection.Font.Bold = True   ActiveCell.FormulaR1C1 = "Hot Prospects"     Selection.End(xlDown).Select   Selection.End(xlDown).Offset(-1, 0).Select   Selection.Font.Bold = True   ActiveCell.FormulaR1C1 = "Hot Prospects on Holds"         Selection.End(xlDown).Select   Selection.End(xlDown).Offset(-1, 0).Select   Selection.Font.Bold = True   ActiveCell.FormulaR1C1 = "Lost Orders"   
End Sub
Should I even worry about effiecency?  It works so quick it wouldn't make a difference.

If it works and is quick it is probably not worth the effort trying to 'optimise' the code. However, if you had code that was looping through hundreds of rows then Selecting would really slow things down.
¥
Back Forum Reply New