Do you have any Excel OCD habits?

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
And leave blank rows in data so auto-filter doesn't filter all data.

I think that there are aot of people that don't quite undetstand how autofilter works. Many select only the header row (e.g. 1:1) and then invoke Auto Filter. With this method excel will attempt to determine the filter range and it will only grab the first area / contiguous range (i.e. last row to the 1st blank row).

One should always select the actual table (e.g. A1:Z100) rather than just the header row, thus explicitly telling excel what the filter range is.
 
One should always select the actual table (e.g. A1:Z100) rather than just the header row, thus explicitly telling excel what the filter range is.

True, but if it's a table of data for analysis rather than presentation it should be kept as one contiguous range anyway. I prefer Alt, D, F, F over making sure I select a range first (haven't progressed past using Excel 2003 key combinations yet for most things).

The introduction of 'Tables' in 2007 was a big help when it came to this, saved a lot of dynamic named ranges for me too.

Nick
 
One should always select the actual table (e.g. A1:Z100) rather than just the header row, thus explicitly telling excel what the filter range is.

I would never do this unless I've got multiple header rows and Excel guesses the wrong one, or the data layout I'm working with is a bit 'interesting'. I wouldn't select the header row either, just a cell in the data table.

Dom
 
Last edited:
Another of mine I just noticed today, I put an extra line in my VBA code after I Dim my variables, after I define my variables, and before/after each parent For, If, and With trees. I find it easier to read and follow.

Example (This is code I wrote for someone a month or two ago):

Code:
Public Sub CutDate()
Dim i As Long, rowx As Long, LR As Long, LC As Long
 
With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With
 
rowx = 1
LR = Sheets("Sheet1").Range("G" & Rows.Count).End(xlUp).Row
LC = Sheets("Sheet1").Cells(2, Columns.Count).End(xlToLeft).Column
 
For i = LR To 2 Step -1
    If Sheets("Sheet1").Range("G" & i).Value > DateSerial(2011, 1, 20) Then
        Sheets("Sheet1").Rows(i).Cut Destination:=Sheets("Sheet2").Range("A" & rowx)
        Sheets("Sheet1").Rows(i).Delete
        rowx = rowx + 1
    End If
Next i
 
With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationAutomatic
End With
 
End Sub
 
I think that there are aot of people that don't quite undetstand how autofilter works. Many select only the header row (e.g. 1:1) and then invoke Auto Filter. With this method excel will attempt to determine the filter range and it will only grab the first area / contiguous range (i.e. last row to the 1st blank row).

One should always select the actual table (e.g. A1:Z100) rather than just the header row, thus explicitly telling excel what the filter range is.

True. I usually use Ctrl+A to select data and a blank row doesn't let me do that too....
 
I tried, I really tried to walk away. But Keith has pushed one of my MrExcel OCD buttons. :nya:

There is always a chance that you will some day take code from an existing routine and copy and paste it into another project where the original routine gets called by a "Main" routine, i.e. the original procedure is now a part of a larger sequence of procedures. You don't want to assume that you are restoring the settings to their original values when the routine was called, you want to know that you're restoring them. In other words.

Code:
...
With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With
...
With Application
    .ScreenUpdating = False      '// <=== hey, I just copied and pasted it, doesn't mean I understood it. :-Þ
    .Calculation = xlCalculationAutomatic
End With
should read
Code:
Dim i As Long, rowx As Long, LR As Long, LC As Long, _
    booScrnUpdt As Boolean, lngCalcMode As XlCalculation
 
With Application
    Let booScrnUpdt = .ScreenUpdating
    Let lngCalcMode = .Calculation
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With
 
'// {snip}
 
With Application
    .ScreenUpdating = booScrnUpdt
    .Calculation = lngCalcMode
End With
 
Last edited:
I tried, I really tried to walk away. But Keith has pushed one of my MrExcel OCD buttons. :nya:

There is always a chance that you will some day take code from an existing routine and copy and paste it into another project where the original routine gets called by a "Main" routine, i.e. the original procedure is now a part of a larger sequence of procedures. You don't want to assume that you are restoring the settings to their original values when the routine was called, you want to know that you're restoring them. In other words.


should read
Code:
Dim i As Long, rowx As Long, LR As Long, LC As Long, _
    booScrnUpdt As Boolean, lngCalcMode As XlCalculation
 
With Application
    Let booScrnUpdt = .ScreenUpdating
    Let lngCalcMode = .Calculation
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
End With
 
'// {snip}
 
With Application
    .ScreenUpdating = booScrnUpdt
    .Calculation = lngCalcMode
End With

I like! Never really thought about handling it in that fashion :biggrin:

Now lets see what other buttons I can find!
 
Those of us born after 1900 can, of course, omit the use of the word 'Let'...
 
Those of us born after 1900 can, of course, omit the use of the word 'Let'...

According to the help file: "Explicit use of the Let keyword is a matter of style"

Maybe Greg just likes to code with style! :rofl:
 

Forum statistics

Threads
1,222,642
Messages
6,167,267
Members
452,107
Latest member
cami_dev

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top