Select Contents of Cell With Macro

MikeG

Well-known Member
Joined
Jul 4, 2004
Messages
845
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I would appreciate if someone could tell me what VBA code to use to highlight the contents of a cell when it is seleted.

So for example, if Cell C4 has the word "Product" in it, then when the user selects that cell, the whole word would be highlighted.

Thanks,

MikeG
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Depends what you mean by highlighted. Yellow background? Bold text?

Should the highlighting be removed when the cell is no longer selected?

Could it apply to a whole selected range or just the active cell?
 
Upvote 0
Depends what you mean by highlighted. Yellow background? Bold text?

Should the highlighting be removed when the cell is no longer selected?

Could it apply to a whole selected range or just the active cell?

Thanks Weaver. I don't mean the format - I mean the text is selected in the same way you can user the cursor to select characters - whether in Excel, Word, webpages etc.

MikeG
 
Upvote 0
Ah, I see what you mean.

I'm not sure that you can. What are you looking to do once they're selected?
 
Upvote 0
Ah, I see what you mean.

I'm not sure that you can. What are you looking to do once they're selected?

Actually, it gets more complicated (!). From MrExcel, I have a macro that creates a "word-complete" for a cell that incorporates a pull-down list. This works well, except that often the user wants to start fresh and not edit the previous entry that was in the cell. So if I can highlight that entry, then they can simply type the first letter of their new word and the existing one will be deleted - if you see what i mean.

This is the behavior for the top-right entry box in Windows Explorer, for example, and I think what most users expet for auto-completion.

Thanks,

MikeG
 
Upvote 0
This also seems to be the behaviour of a normal cell in excel - you select a cell with text and if you start typing, the newly typed text replaces what's already there.

I suspect there's something in the 'autocomplete' text that's preventing this from happening - could you post the code or preferably a link to where I can find it?
 
Upvote 0

Forum statistics

Threads
1,224,545
Messages
6,179,432
Members
452,915
Latest member
hannnahheileen

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