sjk1193

New Member
Joined
Nov 12, 2018
Messages
29
Hi there,

Im getting a runtime error 91 in VBA and cant figure out where the probelm is. I've used this code before and now its not working

Code:
Sub Macro2()


' Defines variables
Dim InputFile As Workbook
Dim OutputFile As Workbook


' Open input / output workbooks:
    With Application.FileDialog(msoFileDialogFilePicker)
        'Makes sure the user can select only one file
        .AllowMultiSelect = False
        .InitialFileName = "S:\PQfolders\Investor Lists"
        'Filter to just the following types of files to narrow down selection options
        .Filters.Add "Excel Files", "*.xlsx; *.xlsm; *.xls; *.xlsb", 1
        .Show
        
        'Store in filepath variable
        filepath = .SelectedItems.Item(1)
    End With
    
Set InputFile = Workbooks.Open(filepath)
Set OutputFile = ThisWorkbook


'-----------------------------------------------------------------------------


Dim Tradedate As Variant
Dim Value As Variant
Dim NBIN As Variant
Dim Name As Variant
Dim Trasaction As Variant
Dim security As Variant
Dim units As Variant
Dim EntityID As Variant
Dim Curr As Variant


Dim i As Long
Dim LR As Long




   InputFile.Sheets(1).Activate
   'inserts column with NBIN Account Number
        ActiveSheet.Cells.Find(what:="Direct Owner", SearchOrder:=xlByColumns).Offset(0, 1).EntireColumn.Insert
        Range("D1") = "NBIN Account Number"
        Range("D2").FormulaR1C1 = "=MID(RC[-1],FIND(""6C"",RC[-1]),7)"
            LR = Range("C" & Rows.Count).End(xlUp).Row
            Range("D2").AutoFill Destination:=Range("D2:D" & LR)
   'inserts column with number of units
        ActiveSheet.Cells.Find(what:="Transaction Units", SearchOrder:=xlByColumns).Offset(0, 1).EntireColumn.Insert
        Range("i1") = "Number of Units"
        Range("i2").FormulaR1C1 = "=ABS(RC[-1])"
            LR = Range("C" & Rows.Count).End(xlUp).Row
            Range("i2").AutoFill Destination:=Range("i2:i" & LR)
            


'finds the transaction column location
InputFile.Sheets(1).Activate
    ActiveSheet.Cells.Find(what:="Trade Date", SearchOrder:=xlByColumns).Select
    
    ' all the relative referances are based on the "Trade Date" column so we have to use the same column order
    For i = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1
    If ActiveCell.Offset(i, 0) <> "" Then


                   Tradedate = ActiveCell.Offset(i, 0)
                   Value = ActiveCell.Offset(i, 1)
                   NBIN = ActiveCell.Offset(i, 3)
                   Name = ActiveCell.Offset(i, 4)
                   Trasaction = ActiveCell.Offset(i, 5)
                   security = ActiveCell.Offset(i, 6)
                   units = ActiveCell.Offset(i, 8)
                   EntityID = ActiveCell.Offset(i, 10)
                   Curr = ActiveCell.Offset(i, 11)


             OutputFile.Activate
                    
                    Range("c44") = Tradedate
                    Range("e44") = Value
                    Range("b29") = NBIN
                    Range("a17") = Name
                    Range("b44") = Trasaction
                    Range("a44") = security
                    Range("j44") = units
                    Range("b31") = EntityID
                    Range("d44") = Curr
                    
            
                ActiveSheet.Name = Range("b29")
                ActiveSheet.Copy After:=ActiveSheet
                'Range("A1:J62").Copy
                
                'Worksheets.Add After:=ActiveSheet
                'ActiveSheet.Paste
                      
        InputFile.Activate
        
        End If
    
    Next


End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Which line of code causes the error?
 
Upvote 0
thats what I'm not sure about. When I F8 into the code the it runs the code until '-----------------------------------------------------------
but then the runtime error message pops up so it doesnt highlight where the error is
 
Last edited:
Upvote 0
There's no option to Debug when the error message pops up?
 
Upvote 0

Forum statistics

Threads
1,215,506
Messages
6,125,189
Members
449,213
Latest member
Kirbito

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