VBA to clear columns but not protected cells

oblix

Board Regular
Joined
Mar 29, 2017
Messages
183
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
  6. 2011
  7. 2010
  8. 2007
  9. 2003 or older
Platform
  1. Windows
  2. MacOS
  3. Mobile
  4. Web
Hi there want to create vba to clear cells on spread sheet
In columns G, and I to AM
The problem is that there are protected cells I dont want to clear
I tried something like this in column h to test but it also clears the protected cells

Sub EmptyStockCount()

On Error Resume Next
Sheets("Blank Stock Sheet").Columns("h:h").Value = vbNullString
On Error GoTo 0

End Sub
Dont understand what I amdoing Wrong
please some assist
 
Unfortunately it is not clearing the data Rick.
Merged cells or what can the problem be.
It runs the code.......without errors, but does not clear anything.
 
Upvote 0

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
My fault... try it this way
VBA Code:
Sub Test()
  Application.FindFormat.Clear
  Application.FindFormat.Locked = False
  Sheets("Blank Stock Sheet").[G:G,I:M].Replace "", "", SearchFormat:=True, ReplaceFormat:=False
  Application.FindFormat.Clear
End Sub
 
Upvote 0
Solution
Still not working Rick
 
Upvote 0
Just so you know, it works fine on my test case with the data I make up which means there is something about your data or sheet that you have not told us about. Can you post a copy of your workbook (desensitize and sensitive info) on DropBox, mark it for sharing and post the link they provide to you here so we can see exactly what your data looks like.
 
Upvote 0
Thanks Rick
I also believe its my data
Will try this DropBox thing
 
Upvote 0

Forum statistics

Threads
1,215,035
Messages
6,122,785
Members
449,095
Latest member
m_smith_solihull

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