PC Review


Reply
Thread Tools Rate Thread

almost there ... code modify help

 
 
Ray
Guest
Posts: n/a
 
      29th Mar 2007
Hello -

I'm trying to modify some code I got from this Group and can't quite
seem to make it work ... hopefully, someone can help me out....

The code is supposed to -- go to each specified sheet, and value-out
links in light yellow cells, replacing #N/A with "". The code worked
fine before I tried to make it unprotect each sheet and replace the #N/
A's. I'd also like the code to ONLY re-protect sheets that were
originally protected -- the code currently doesn't address this need
at all.

Sub AABB()
Dim i As Long
Dim sh As Worksheet
Dim rng As Range
vArr = Array("P&L Summary", "P&L Acct Detail", "SALES", "FC
Scenarios", "CALCRENTALEQUP", "Capital Request 07", "Capital Request
08", "CALCINV", "GPR")
For i = LBound(vArr) To UBound(vArr)
Set sh = Worksheets(vArr(i))
sh.Unprotect Password:="busnav"
Set rng = sh.UsedRange
rng.Select
For Each Cell In Selection
Select Case Cell.Interior.ColorIndex
Case 36
Cell.Value = Cell.Value
End Select
Next Cell

sh.UsedRange.Replace What:="#N/A", Replacement:="",
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
Range("A1").Select

sh.Protect Password:="busnav", DrawingObjects:=True,
Contents:=True, Scenarios:=True _
, AllowFormattingColumns:=True
Next
End Sub


TIA for any help you can provide ....

Rgds, Ray

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9lbA==?=
Guest
Posts: n/a
 
      29th Mar 2007
I added an activate statement to get it to run

Sub AABB()
Dim i As Long
Dim sh As Worksheet
Dim rng As Range
vArr = Array("P&L Summary", "P&L Acct Detail", "SALES", "FC Scenarios", _
"CALCRENTALEQUP", "Capital Request 07", "Capital Request 08", "CALCINV",
"GPR")
For i = LBound(vArr) To UBound(vArr)
Set sh = Worksheets(vArr(i))
sh.Unprotect Password:="busnav"
Worksheets(vArr(i)).Activate
Set rng = sh.UsedRange
rng.Select
For Each Cell In Selection
Select Case Cell.Interior.ColorIndex
Case 36
Cell.Value = Cell.Value
End Select
Next Cell

sh.UsedRange.Replace What:="#N/A", Replacement:="", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
Range("A1").Select

sh.Protect Password:="busnav", DrawingObjects:=True, _
Contents:=True, Scenarios:=True _
, AllowFormattingColumns:=True
Next
End Sub


"Ray" wrote:

> Hello -
>
> I'm trying to modify some code I got from this Group and can't quite
> seem to make it work ... hopefully, someone can help me out....
>
> The code is supposed to -- go to each specified sheet, and value-out
> links in light yellow cells, replacing #N/A with "". The code worked
> fine before I tried to make it unprotect each sheet and replace the #N/
> A's. I'd also like the code to ONLY re-protect sheets that were
> originally protected -- the code currently doesn't address this need
> at all.
>
> Sub AABB()
> Dim i As Long
> Dim sh As Worksheet
> Dim rng As Range
> vArr = Array("P&L Summary", "P&L Acct Detail", "SALES", "FC
> Scenarios", "CALCRENTALEQUP", "Capital Request 07", "Capital Request
> 08", "CALCINV", "GPR")
> For i = LBound(vArr) To UBound(vArr)
> Set sh = Worksheets(vArr(i))
> sh.Unprotect Password:="busnav"
> Set rng = sh.UsedRange
> rng.Select
> For Each Cell In Selection
> Select Case Cell.Interior.ColorIndex
> Case 36
> Cell.Value = Cell.Value
> End Select
> Next Cell
>
> sh.UsedRange.Replace What:="#N/A", Replacement:="",
> LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
> Range("A1").Select
>
> sh.Protect Password:="busnav", DrawingObjects:=True,
> Contents:=True, Scenarios:=True _
> , AllowFormattingColumns:=True
> Next
> End Sub
>
>
> TIA for any help you can provide ....
>
> Rgds, Ray
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Archive code -- modify my code! Ray Microsoft Outlook VBA Programming 3 17th Nov 2009 09:16 PM
How can I modify my code to offset the defined range and repeat theprocedure instead of duplicating my code? najisaadat@gmail.com Microsoft Excel Programming 4 29th May 2009 10:13 PM
Chip Pearson's code to modify code Otto Moehrbach Microsoft Excel Programming 2 9th Nov 2007 11:25 PM
Modify existing code to dynamic code Ixtreme Microsoft Excel Programming 5 31st Aug 2007 11:42 AM
Using Code to modify Code in MS Word =?Utf-8?B?a2VpdGggSA==?= Microsoft Access VBA Modules 1 18th Feb 2005 08:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:10 AM.