Code referencing another workbook - error

sspicer

New Member
Joined
Jun 27, 2008
Messages
48
I have the following code in my workbook.

I want it to take the values of cells in the current workbook and scroll through another workbook to see if the value is present in there, and then perform a function if it is - else do nothing.

The line preceeded with a lot of ***** is the line where the error occurs in the code. It says subscript out of range, and I can't work out why.

Any ideas?!?! Please help!!!



Code:
Sub Button1_Click()
    
    Dim LastVersion As Integer
    Dim FileString As String
    Dim PreviousIssue As String
    Dim i, j As Integer
    Dim CurrentName As String
        
    With Application
        .ScreenUpdating = False
        .Calculation = xlCalculationManual
    End With
    
        FileString = Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 6)
        LastVersion = Left(Right(ThisWorkbook.Name, 6), 1) - 1
        PreviousIssue = FileString & LastVersion & ".xlsm"
    
    Application.Workbooks.Open (PreviousIssue)
    
    i = 6
    j = 6
    
    Do Until IsEmpty(Sheets("Member Details").Range("B" & i))
        CurrentName = ThisWorkbook.Sheets("Member Details").Range("B" & i) & "_" & ThisWorkbook.Sheets("Member Details").Range("C" & i)
        
     *******  Do Until IsEmpty(Workbooks(PreviousIssue).Sheets("MemberData").Range("B" & j))
            If Workbooks(PreviousIssue).Sheets("Member Details").Range("B" & i).Value & "_" & ThisWorkbook.Sheets("Member Details").Range("C" & i).Value = CurrentName Then
            'do something
            Else: j = j + 1
            End If
       Loop
            
        i = i + 1
    Loop
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Maybe:

Code:
Do Until Workbooks(PreviousIssue).Sheets("MemberData").Range("B" & j) = ""

IsEmpty is generally used for checking if a variable is empty or not, rather than for checking cell values I think.

Dom
 
Last edited:
Upvote 0
Are you sure the sheet is called "MemberData" and not say "Member Data" with a space?
 
Upvote 0
Yes, it is "Member Data", you're right. However, the code still errors...

I'm going to trying the = "" instead of isempty to see if that works...
 
Upvote 0
have just realised the error ... I'm sorry for wasting your time and feel a bit silly .. is Member Details ... thank you both for your quick response...

:oops:
 
Upvote 0

Forum statistics

Threads
1,215,945
Messages
6,127,840
Members
449,411
Latest member
adunn_23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top