12

I would like the final appearance after my VBA has finished running to be empty of selection -- to have no cell or range on any sheet colored (if it was range selected) or in a bold line box (anything that was selected). Pupose: to present the client with a neat final appearance.

I've searched and cannot find how to do this. There is an Unselect according to MS, but it doesn't seem to do anything.

3
  • Why don't you select cell A1 when you save to present a clean look. If you want to strip cell formatting that is a different thing.
    – wbeard52
    Sep 4, 2012 at 0:09
  • The cursor has to be somewhere. Why not place it bottom right with Worksheets("xxxx").Cells(Rows.Count,Columns.Count).Select or anywhere that is at least a screen away from the used area. Sep 4, 2012 at 8:16
  • could you just place it back where it was when the macro was called?
    – SeanC
    Sep 4, 2012 at 15:45

10 Answers 10

10

Select any cell and turn off CutCopy:

  Range("A1").Select
  Application.CutCopyMode = False
2
  • Yup, perfect for me. Thanks. I had a VBA macro that copied some cells from one workbook to another and then closed the source workbook, but because some cells were still selected for copy in the source it wouldn't close right away. Application.CutCopyMode = False fixed that for me. Thanks bud!
    – TKoL
    Dec 29, 2016 at 10:10
  • Side effect: clears the clipboard. stackoverflow.com/a/17608260/733092
    – Noumenon
    Mar 5, 2019 at 3:38
3

Excel always has something selected. A work around is needed. Selecting a cell off screen will set focus there, so that won't work in and of itself. This code places the cursor off screen and then scrolls the sheet back up to view A1.

Sub NoSelect()    
  Range("BB100").Select
  ActiveWindow.SmallScroll up:=100
  ActiveWindow.SmallScroll ToLeft:=44
End Sub

If you are really wanting 'nothing selected`, you can use VBA to protect the sheet at the end of your code execution, which will cause nothing to be selected. You can either add this to a macro or put it into your VBA directly.

Sub NoSelect()
   With ActiveSheet
   .EnableSelection = xlNoSelection
   .Protect
   End With
End Sub

As soon as the sheet is unprotected, the cursor will activate a cell.

2

There is a tricky way to do it.

Create an object such as a button. Select this button, then hide it, and no cell will be selected.

ActiveSheet.Shapes("Button 1").Visible = True

ActiveSheet.Shapes("Button 1").Select

ActiveSheet.Shapes("Button 1").Visible = False

That's it.

1

The only answer is to cheat.

Hide column A and row 1

Put cursor in A1. There will be a tiny dot in the corner of B2

2
  • or you could select a cell outside of the viewable range. Sep 5, 2012 at 18:21
  • @KronoS, which at 10% zoom, and a 1280x1024 screen is ~HA375. perhaps XFD1048576 ? :)
    – SeanC
    Sep 5, 2012 at 18:25
1

Depending on the size of your selection, to get rid of any artifacting (I don't know if this is also an issue in 2013 Excel, but on Mac it was a constant pain for me) you can just loop through cell by cell and select each.

1

By turning off screen updating before selecting a cell, scroll to selected cells is temporarily disabled.

This code checks which cells are currently visible and selects the first cell below the visible range which is not in view. Eg, when i try it: Visble range is A1:BC79, so this code selects A80 and scrolling down and to the right and running it again reveals the excel chooses the first cell NOT visible below the first visible column.


Dim r As Range
Application.ScreenUpdating = False
Set r = Application.ActiveWindow.VisibleRange
r(r.Cells.Count + 1).Select
Application.ScreenUpdating = True

0
1

Very old question, but my answer for reference:

You can use

With ActiveSheet
    .EnableSelection = xlNoSelection
    .Protect
End With
1

Put it under the last row:     Application.SendKeys ("{ESC}")
It will release the selection.

0

Use a trick: Add a shape, then select it and hide it.

Source code for this is in answer of different question on this site.

0

You can simply select another cell.

for eg:

Sheets("Sheetname").cells(1,1).select

This will select the a1 cell.

1
  • Welcome to Super User! Before answering an old question having other answers ensure your answer adds something new or is otherwise helpful in relation to them. Here is a guide on How to Answer. There is also a site tour and a help center. Aug 1, 2022 at 15:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .