• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Compline Error when Click on Execute button

SDB

New Member
Hi , I am half through to create user form .
Just in when I click on EXECUTE button to run the code I get "compile error" - Invalid or Unqualified reference"
Can anyone help me here please, thank you

Code:
Private Sub CommandButton2_Enter()
Do
                  If xFound Is Nothing Then
                    Exit Do
                    Else
                        xCount = xCount + 1
                        xRow = xRow + 1
                
                        .Cells(xRow, 1) = xWb.Name
                        .Cells(xRow, 2) = xWk.Name
                        .Cells(xRow, 3).Formula = "=HYPERLINK(""" & xWb.FullName & """)"
                        .Cells(xRow, 4).Range("A1:BA1").Value = xFound.EntireRow.Range("A1:BA1").Value
                        
                    End If
                    Set xFound = xWk.Cells.FindNext(After:=xFound)
                Loop While xStrAddress <> xFound.Address
            Next
            xWb.Close (False)
            xStrFile = Dir
        Loop
        .Columns("A:D").EntireColumn.AutoFit
    End With
    MsgBox xCount & "cells have been found", , "Result"
ExitHandler:
    Set xOut = Nothing
    Set xWk = Nothing
    Set xWb = Nothing
    Set xFld = Nothing
    Set xFso = Nothing
    Application.ScreenUpdating = xUpdate
    Exit Sub
ErrHandler:
    MsgBox err.Description, vbExclamation
    Resume ExitHandler
End Sub
 
When you get the error, click on Debug and tell us which line of code is highlighted. Without this information, it is kind of difficult to diagnose .
 
.Cells(xRow, 1) = xWb.Name
Hi, I get the error on above statement.

If i add say WB. In front of. Cells then the error shifts to Next, above xwb. Close(false) as mentioned below.

Next
xWb.Close (False)
 
SDB
Why ... did You 'clean' from above code some needed as well as lines which You have in this Your thread?
That seems to have almost same code ... hmm?
If You have eg .Cells(xRow, 1) then many times there should be sheet too, as You already know!
... without that 'pre-dot' case could be different.
 
Well, In my other post there was no response, so i tried to create the form myself but encountered the compile error.
 
SDB
Well ...?
There were none ... well ... question.

Hint 1: if no response then You should reread from
How to get the Best Results at Chandoo.org

Hint 2: Excel has rules ~ like a grammar, how those codes should write.
If You skip those rules, then Excel won't understand You.
If Excel cannot understand You, then the result could be something else or ... it would give note, that something should modify.
If You want to modify others code, then do it a little by little until You know - what to do.
 
Back
Top