LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default error in my VBA (newbie)

I do not normally work in Excel. We (the IT dept at my company) have an
Excel workbook that we inherited from... somewhere. Someone asked me to do
one simple thing. I did it. The problem is I did it on a protected sheet.
While working on the functionality they wanted, I simply unprotected the
sheet so I could change it. And now I am trying to get it to work with the
sheet protected.

I have 2 locked cells, that need to be locked, which is why I need to
protect the sheet.

OK, so I have a button which does this:

Range("D14") = GetTotalInterest(Range("D6"), Range("D10"), Range("D12"),
Range("D8"))

Where GetTotalInterest is a function which returns a double. D14 is one of
the "locked" cells because the folks are not supposed to be able to type
into it. So I need to protect the sheet, which will cause me not to be able
to do

Range("D14") =

Fine. So I try this instead:

Sheets("Variable").Unprotect "pwd"
Range("D14") = GetTotalInterest(Range("D6"), Range("D10"), Range("D12"),
Range("D8"))
Sheets("Variable").Protect "pwd"

Where "pwd" is a not terribly necessary password. The person who created the
sheet, protected with a password. So ... I thought I would continue that
trend, even though it is not terribly important to do so. I get the error:

Unprotect method of Worksheet class failed (number 1004).

I do not know why. I am supplying the correct password in the correct case.
The help on the error message is not helpful.

Anyone have any ideas what I am doing wrong?

Included here is the code for GetTotalInterest. It has an unprotect and
protect in it. So I note it in case it helps.

Function GetTotalInterest(LoanAmt As Double, PayAmt As Double, ActualTerm As
Double, InterestRate As Double) As Double

Dim totalinterest As Variant

Dim e10, e11, e12, e13, e17

' Application.ScreenUpdating = False
'modUtilities.cmd_Clear_Consolidation



Sheets("Consolidation").Select


With Sheets("Consolidation")
.Unprotect ("estimate")
e10 = .Range("E10").Formula
e11 = .Range("E11").Formula
e12 = .Range("E12").Formula
e13 = .Range("E13").Formula
e17 = .Range("E17").Formula


.Range("E12") = LoanAmt ' loan amount
.Range("E11") = LoanAmt
.Range("E13") = PayAmt ' payment amount
.Range("E17") = ActualTerm ' actual term
.Range("E10") = InterestRate ' interest rate
totalinterest = .Range("E15")


.Range("E10").Formula = e10
.Range("E11").Formula = e11
.Range("E12").Formula = e12
.Range("E13").Formula = e13
.Range("E17").Formula = e17
.Protect ("estimate")

End With




GetTotalInterest = totalinterest

modUtilities.cmd_Clear_Consolidation
Sheets("Variable").Select
Application.ScreenUpdating = True


End Function

THANKS!

S


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
vba newbie need help. Oligo Excel Discussion (Misc queries) 2 November 5th 08 07:22 PM
newbie ? Charles Eaves New Users to Excel 1 July 28th 08 09:11 AM
Real Newbie newbie question Dave New Users to Excel 0 January 10th 07 07:55 PM
newbie needs help p-nut Charts and Charting in Excel 2 November 15th 06 02:13 PM
Compile error: Ambigious name detected: Worksheet_Change **NEWBIE** dan Excel Discussion (Misc queries) 1 May 26th 06 10:13 AM


All times are GMT +1. The time now is 11:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"