Macros and protecting a cell

Status
Not open for further replies.

Lurch65

Banned user
Joined
Oct 4, 2024
Messages
7
Office Version
  1. 365
Platform
  1. Windows
For my work I need to strip down part numbers to remove spaces, so created this Macro with find and replace:

Sub Macro1()

'

' Macro1 Macro

'



'

ActiveCell.Replace What:=" ", Replacement:="", LookAt:=xlPart, _

SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _

ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2

Cells.Find(What:=" ", After:=ActiveCell, LookIn:=xlFormulas2, LookAt:= _

xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _

, SearchFormat:=False).Activate

End Sub

The sheet looks like this:

Macro.png
 

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.
When I paste into the box and slide over to my click here button, it works like a charm, but if I catch the button a second time it takes spaces out of other text!

if I unlock the box and then protect the sheet, the macro no longer works.

Ideally I want the Macro to only work on the one cell, my search box.

Even better would be for the Macro to work without having to click the button, the pasted text immeadiately appearing with spaces removed. Is that possible, and, if not, how to do at least prevent the macro from being overly aggressive?
 
Upvote 0
I did not expect 200 views and no help?

Has this place lost what it once was?
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Sheet protection preventing Macro?
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
I got no answer here so tried somewhere else.



Really not sure Fluff how your answer is:



A)Helpful



B)Not making the mods here look like control freaks



C)Not making the whole excel community look petty and truculent
 
Upvote 0
With that attitude, you're no longer welcome here.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,704
Messages
6,173,984
Members
452,540
Latest member
haasro02

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