1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

VB error - does not recognize Left function

Discussion in 'Software Development' started by EdBurkett, Jul 12, 2006.

Thread Status:
Not open for further replies.
  1. EdBurkett

    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.
     
  2. dquigley

    dquigley

    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
     
  3. cristobal03

    cristobal03

    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.
     
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 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/482535

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice