VB error - does not recognize Left function

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

EdBurkett

Thread Starter
Joined
Jul 12, 2006
Messages
1
Hello all,

I have a very perplexing problem. I maintain an Excel spreadsheet for my company that contains numerous VBA Macros. On some systems/installations of Excel, macros are crashing because a standard command is not recognized. The same macro will run on different versions of Excel and on the same version but a different installation.

The specific error message is "Compile Error: Can't find project or library"

Does anyone have any ideas about why this occurs and/or a different approach to this bit of code?

Below is the currently offending code. The Left function is currently causing the problem though I have had problems with other standard functions in the past.

Dim c, OldText, NewLen, NewText
If _
Worksheets("BOM_1").Range("AB96").Formula "RENT" _
Then
With Worksheets("BOM_1")
.Unprotect
.Range("AB96").Formula = "RENT"
.Range("F33").FormulaR1C1 = "=sum(R100C9:R2299C9)"
.Range("E41:F43").ClearContents
.Rows("41:43").RowHeight = 0
For Each c In .Range("E307:E312,E332:E343")
OldText = c.Formula
NewLen = Len(OldText) - 10
NewText = Left(OldText, NewLen)
c.Formula = NewText
c.Font.ColorIndex = xlAutomatic
Next c

Thanks in advance for any help you can give.
 
Joined
Apr 17, 2006
Messages
112
I can't think of any reason it would say that so it could be a corrupt or missing vba dll.
You may want to re-install Excel on that machine, wouldn't hurt to double check for a virus.

When you type Left( into the vba editor, does a tool tip pop up with the parameters?

There are some structure issues with the code that will prevent it from compiling.

1) missing operator (= sign presumably) in the if statement

2) missing End With and End If statements after the Next c statement

There is a potential for a runtime error if Len(OldText) < NewLen in this statement

Code:
NewText = Left(OldText, NewLen)
Making a number of assumptions this would be one way to write this:

Code:
    Dim c, OldText, NewLen, NewText
    If Worksheets("BOM_1").Range("AB96").Formula = "RENT" Then
        With Worksheets("BOM_1")
            .Unprotect
            .Range("AB96").Formula = "RENT"
            .Range("F33").FormulaR1C1 = "=sum(R100C9:R2299C9)"
            .Range("E41:F43").ClearContents
            .Rows("41:43").RowHeight = 0
            For Each c In .Range("E307:E312,E332:E343")
                OldText = c.Formula
                NewLen = Len(OldText) - 10
                If (NewLen > 0) Then
                    NewText = Left(OldText, NewLen)
                    c.Formula = NewText
                    c.Font.ColorIndex = xlAutomatic
                Else
                    'do something here if needed
                End If
            Next c
        End With
    End If
Dan
 
Joined
Aug 5, 2005
Messages
3,086
Left is part of the VBA library; if that was missing, you'd have errors with just about every line of your code. It may however be corrupt, or there may be some sort of naming conflict. The default location is

C:\Program Files\Common Files\Microsoft Shared\VBA\VBA rev\
That folder should contain a number of DLLs depending on your current installation revision. You could locate the matching DLLs on your installation CD and copy them over. My money's on some sort of naming conflict though; if the VBA DLL was really broken, you wouldn't be able to get anywhere with any kind of scripting whatsoever.

chris.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Top