473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Clear Contents of unprotected Specific Range in a protected sheet

5
I want to clear the unprotected contents of a protected sheet within a specific range. for example when i run VBA it will clear the contents ranging from A1002:F1301 and G1002: AZ1301. The mentioned ranges are unprotected. I want only the cell between these range to ne clear but not format or any other change . How can i do this ?
Jul 24 '16 #1
6 1352
ADezii
8,834 Expert 8TB
I am a little confused about you request. From my interpretation you wish to clear all Cells within a specified, unprotected Range except a single Cell within that Range. If this is so, then the following Macro will do the trick, it will clear all Cells within the Range $A$1002:$F$1301 except $C$1016.
Expand|Select|Wrap|Line Numbers
  1. Dim rng1 As Excel.Range
  2. Dim rng2 As Excel.Range
  3.  
  4. Set rng1 = Worksheets("Sheet1").Range("A1002:F1301")
  5.  
  6. For Each rng2 In rng1
  7.   If rng2.Address <> "$C$1016" Then
  8.     rng2.ClearContents
  9.   End If
  10. Next
Jul 24 '16 #2
zmbd
5,501 Expert Mod 4TB
ADezii, I think a typo here, "cell" might have been "cells" given that these are adjacent ranges.
Expand|Select|Wrap|Line Numbers
  1. Sub poc()
  2.     ThisWorkbook.Worksheets("Sheet1").Range("A1002:AZ1301").ClearContents
  3. End Sub
will do the trick.

If this isn't the case then auhom needs to clarify the question.
Jul 24 '16 #3
ADezii
8,834 Expert 8TB
Thanks zmdb for the clarification. For my own curiosity, what is your opinion on using?
Expand|Select|Wrap|Line Numbers
  1. ActiveWorkbook vs. ThisWorkbook
Jul 24 '16 #4
zmbd
5,501 Expert Mod 4TB
I personally have two to 15 different workbooks open at a time at work and having ran afoul of executing code and having the wrong workbook effected, I tend to use "ThisWorkBook" over "ActiveWorkbook".
Jul 25 '16 #5
MikeTheBike
639 Expert 512MB
Hi zmbd

I very rarely use ThisWorkbook as it will refer to the workbook in which the running code is written. I hardly ever read or write info to/from the workbook that is running the code.

From memory I only use ThisWorkbook for checking that the user has not selected this file to open ie = ThisWorkbook.Name (in addition to checking the selected file is not already open).
Jul 25 '16 #6
ADezii
8,834 Expert 8TB
@zmbd and Mike:
Thanks for tour input.
Jul 25 '16 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Rob Videtta | last post by:
Hi, Please Help! I have developed a custom JSP tag that produces Javascript to create a window and write HTML and Javascript to that window. This window displays an error message. The...
0
by: rshillington | last post by:
I have one content page that need a stylesheet that is in addition to the styles coded in the CSS for the theme. Since the content page doesn't have a HEAD element, how do I add a LINK to the...
2
by: tkhouk | last post by:
I have a small form with two unbound look-up fields (one for an ID and one for last name). Each unbound field has a command button that actually goes to my table and brings in the records. How can...
4
by: moondaddy | last post by:
Using c# 3.5, what's the best way to remove the contents of a stringbuilder object? I was using this code: sb.Remove(1, sb.Length - 1); but when it had 9 carriage returns in it like this:...
3
by: jamieharrop | last post by:
Afternoon all, I've been battling with this all day today and my brain is now pretty much fried. I have one table that lists several details about my customers (name, address, phone, date of...
13
by: raghavendrap | last post by:
Hello Friends, I am doing randomization of intergers for specific range.The way i have done is mentioned below. use strict; my @id; my $idx1; my $idx2; my $idx3; my...
1
by: shahnawazatiq | last post by:
sirs, can anybody give me the VB code for how to copy user specific data from one workbook to other workbook . example:i am having database on one workbook say "data1" and one other workbook say...
11
by: CarrieR | last post by:
Hi, I thought this was a simple issue, but apparently it's not. I need to export the contents of about 30 queries, each into a specific sheet, and cell range, of an existing Excel workbook. ...
0
by: Cara Sikes | last post by:
I am trying to create a custom function attached to a graphic which will allow for the contents of a range (on a single row) of cells to be cleared when activated. I would like to be able to perform...
3
by: Exlq | last post by:
Can you please help. I need to import/Link excel sheet(specific range)in ms access. The range varies everytime we get the new excel sheet due to addition and deletion of records so want to make the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.