+ Reply to Thread
Results 1 to 14 of 14

Run time error 91 on datas

Hybrid View

  1. #1
    Registered User
    Join Date
    03-23-2023
    Location
    Paris
    MS-Off Ver
    365
    Posts
    8

    Question Run time error 91 on datas

    Good Morning

    Have a run time error 91 on my code but not every time

    using the find function to find a date then xxx.row

    Datas I'm looking for are timestamp, it is working between 10:00:00 and 12:45:00 but not before or after

    Find below the code, issue is on 'PUTTING TIME STAMP section
    Adding also 2 printscreen

    Need some help, it drives me crazy timexcel.PNGtimestamp.PNG

    Public wb As ThisWorkbook
    Public WsP As Worksheet
    Public WsTR As Worksheet
    Public WsTI As Worksheet
    Public WsM As Worksheet
    
    Sub TRANSFERT()
    
    Set wb = ThisWorkbook
    Set WsP = Sheets("PARAMS")
    Set WsTR = Sheets("TRANSFERT")
    Set WsTI = Sheets("TICKER")
    Set WsM = Sheets("MARKETS")
    
    Dim R As Integer
    Dim R1 As Byte
    Dim C As Integer
    Dim debut As String
    Dim fin As String
    Dim slices As String
    Dim ouverture As String
    Dim fermeture As String
    Dim volume As String
    Dim volume2 As Integer
    Dim mtf As String
    Dim avg As String
    Dim place As String
    Dim Rng1 As Range
    Dim somme As Long
    Dim adresse As Integer
    Dim adresse1 As Integer
    Dim adresse2 As Integer
    
    Application.ScreenUpdating = False
    
    ' DELETE WSTR
    
    WsTR.Select
    Range("A:PPA").Delete
    
    ' STRING DEFINITION
    
    WsP.Select
    
    debut = Format(Range("F11").Value, "hh:mm:ss")
    fin = Format(Range("K11").Value, "hh:mm:ss")
    slices = Range("P11").Value
    ouverture = Range("F13").Value
    fermeture = Range("K13").Value
    volume = Range("P13").Value
    mtf = Range("F15").Value
    place = WsTI.Cells(1, 6).Value
    
    'COPYPASTE AVG
    
    If volume = "30D" Then
        avg = "VOLUME_AVG_30D"
        Else
        If volume = "20D" Then
            avg = "VOLUME_AVG_20D"
            Else
            If volume = "10D" Then
                avg = "VOLUME_AVG_10D"
                Else
            End If
        End If
    End If
    
    WsTI.Select
    
    R = Application.WorksheetFunction.CountA(Range("A:A"))
    C = ActiveSheet.UsedRange.Columns.Count
    
    Range(Cells(3, 1), Cells(R, C)).Copy
    
    WsTR.Select
    
    Cells(1, 1).PasteSpecial xlValues
    Cells(1, 1).PasteSpecial xlFormats
    
    R = ActiveSheet.UsedRange.Rows.Count
    
    For i = C To 4 Step -1
        If Cells(1, i).Value = avg Then
            Else
            Columns(i).EntireColumn.Delete
        End If
    Next i
    
    For i = R To 2 Step -1
        If Cells(i, 4).Value = "" Or Cells(i, 4).Value = 0 Or Cells(i, 4).Value = "#N/A N/A" Then
            Rows(i).EntireRow.Delete
            Else
        End If
    Next i
    
    R = ActiveSheet.UsedRange.Rows.Count
    
    Set Rng1 = Range(Cells(2, 4), Cells(R, 4))
    somme = WorksheetFunction.Sum(Rng1)
    
    For i = 2 To R
        Cells(i, 5).Value = Cells(i, 4) / somme
    Next i
    
    Cells(1, 5).Value = "PERCENTAGE"
    Cells(1, 4).Copy
    Cells(1, 5).PasteSpecial xlFormats
    
    Range("E:E").Copy
    Range("E:E").PasteSpecial xlValues
    
    ' REDEFINING VOLUME STRING
    
    If volume = "30D" Then
        volume = 30
        Else
        If volume = "20D" Then
            volume = 20
            Else
            volume = 10
        End If
    End If
    
    ' PUTTING TIME STAMP
    
    WsM.Select
    
    Set trouver = [B:B].Find(place, LookAt:=xlPart)
    adresse = trouver.Row
    
    Set trouver1 = [R:R].Find(debut, LookAt:=xlPart)
    adresse1 = trouver1.Row
    
    Set trouver2 = [R:R].Find(fin, LookAt:=xlPart)
    adresse2 = trouver2.Row
    
    If ouverture = "Yes" Then
        Cells(adresse, 3).Copy
        WsTR.Select
        Cells(R + 5, 1).PasteSpecial xlValues
        Cells(R + 5, 1).PasteSpecial xlFormats
        WsM.Select
        Cells(adresse, 4).Copy
        WsTR.Select
        Cells(R + 5, 2).PasteSpecial xlValues
        Cells(R + 5, 2).PasteSpecial xlFormats
        Cells(R + 5, 2).Copy
        Cells(R + 6, 1).PasteSpecial xlValues
        Cells(R + 6, 1).PasteSpecial xlFormats
        WsM.Select
        Set Rng1 = Range(Cells(adresse1 + 1, 18), Cells(adresse2 - 1, 18))
        For Each cel In Rng1
            cel.Copy
            WsTR.Select
            R1 = Application.WorksheetFunction.CountA(Range("A:A"))
            Cells(R1 + 5, 1).PasteSpecial xlValues
            Cells(R1 + 5, 1).PasteSpecial xlFormats
            WsM.Select
        Next
        WsM.Select
        Set Rng1 = Range(Cells(adresse1 + 1, 18), Cells(adresse2, 18))
        For Each cel In Rng1
            cel.Copy
            WsTR.Select
            R1 = Application.WorksheetFunction.CountA(Range("B:B"))
            Cells(R1 + 5, 2).PasteSpecial xlValues
            Cells(R1 + 5, 2).PasteSpecial xlFormats
            WsM.Select
        Next
        Else
        Cells(adresse1, 18).Copy
        WsTR.Select
        Cells(R + 5, 1).PasteSpecial xlValues
        Cells(R + 5, 1).PasteSpecial xlFormats
        WsM.Select
        Cells(adresse1 + 1, 18).Copy
        WsTR.Select
        Cells(R + 5, 2).PasteSpecial xlValues
        Cells(R + 5, 2).PasteSpecial xlFormats
        WsM.Select
        Set Rng1 = Range(Cells(adresse1 + 1, 18), Cells(adresse2 - 1, 18))
        For Each cel In Rng1
            cel.Copy
            WsTR.Select
            R1 = Application.WorksheetFunction.CountA(Range("A:A"))
            Cells(R1 + 5, 1).PasteSpecial xlValues
            Cells(R1 + 5, 1).PasteSpecial xlFormats
            WsM.Select
        Next
        WsM.Select
        Set Rng1 = Range(Cells(adresse1 + 2, 18), Cells(adresse2, 18))
        For Each cel In Rng1
            cel.Copy
            WsTR.Select
            R1 = Application.WorksheetFunction.CountA(Range("B:B"))
            Cells(R1 + 5, 2).PasteSpecial xlValues
            Cells(R1 + 5, 2).PasteSpecial xlFormats
            WsM.Select
        Next
    End If
    
    WsM.Select
    
    If fermeture = "Yes" Then
        Range(Cells(adresse, 5), Cells(adresse, 6)).Copy
        WsTR.Select
        R1 = Application.WorksheetFunction.CountA(Range("A:A"))
        Cells(R1 + 5, 1).PasteSpecial xlValues
        Cells(R1 + 5, 1).PasteSpecial xlFormats
        Else
    End If
    
    ' PUTTING MTF
    
    WsTR.Select
    
    R1 = Application.WorksheetFunction.CountA(Range("C:C"))
    
    volume2 = (volume * (R - 1) + 2)
    
    For i = 3 To volume2
        Range(Cells(2, 3), Cells(R, 3)).Copy
        Cells(R + 4, i).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
        i = i + R - 2
    Next i
    
    ' PUTTING DATE
    
    WsM.Select
    
    j = 3
    For i = 2 To volume + 1
        Cells(i, 15).Copy
        WsTR.Select
        Cells(R + 3, j).PasteSpecial xlValues
        Cells(R + 3, j).PasteSpecial xlFormats
        j = j + R - 1
        WsM.Select
    Next i
    
    WsM.Select
    
    R1 = Application.WorksheetFunction.CountA(Range("A:A"))
    C = ActiveSheet.UsedRange.Columns.Count
    
    
    WsP.Select
    Cells(1, 1).Select
    
    Application.ScreenUpdating = True
      
    End Sub

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Run time error 91 on datas

    Your code is not finding debut in Col R

    Set trouver1 = [R:R].Find(debut, LookAt:=xlPart)
    If Not trouver1 is Nothing then
        adresse1 = trouver1.Row
    Else
        MsgBox debut & " Not Found"
    End If
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    03-23-2023
    Location
    Paris
    MS-Off Ver
    365
    Posts
    8

    Re: Run time error 91 on datas

    Hi Sintek,

    trouver1 and trouver 2 are for column K not B
    My issue it is working for a certain time stamp but not for all and I'm sure the data to find is in Column K cos I have done a validation list....

    really drives me crazy ...

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Run time error 91 on datas

    trouver1 and trouver 2 are for column K not B
    You mean Col R
    My post was amended prior to your response...
    See yellow manner above regarding sample file and explain what it is you are wanting to achieve...

  5. #5
    Registered User
    Join Date
    03-23-2023
    Location
    Paris
    MS-Off Ver
    365
    Posts
    8

    Re: Run time error 91 on datas

    My bad ... did not see

    I want to find the correct Row but I don't understand why sometimes I have this runtime error for time prior 10:00:00 and after 12:45:00

    thx

    Mathieu

  6. #6
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Run time error 91 on datas

    Can only ascertain once we see your file...Dates and times are tricky and often one has to manipulate...

  7. #7
    Registered User
    Join Date
    03-23-2023
    Location
    Paris
    MS-Off Ver
    365
    Posts
    8

    Re: Run time error 91 on datas

    with pleasure
    how Can I add it ?

  8. #8
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Run time error 91 on datas

    See Yellow Banner above thread...HOW TO ATTACH YOUR SAMPLE WORKBOOK:

  9. #9
    Registered User
    Join Date
    03-23-2023
    Location
    Paris
    MS-Off Ver
    365
    Posts
    8

    Re: Run time error 91 on datas

    PRETRADE MB.xlsm

    U got it

  10. #10
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Run time error 91 on datas

    And now...Explain the process as this file has no entries?

  11. #11
    Registered User
    Join Date
    03-23-2023
    Location
    Paris
    MS-Off Ver
    365
    Posts
    8

    Re: Run time error 91 on datas

    So F11 / K11 is scrolling menu based on list on Markets worksheets

    F13/K13/P13 are scrolling menu with data who are not impacting the process of the macro

    G20 is Bloomberg ticker ie : ORA FP
    N20 is a number ie 50.000
    U20 is Buy or Sell



    Here the issue when I'm running the macro it is working between 10:00:00 and 12:45:00 but not if I'm putting an time stamp before or after

  12. #12
    Registered User
    Join Date
    03-23-2023
    Location
    Paris
    MS-Off Ver
    365
    Posts
    8

    Re: Run time error 91 on datas

    Solved on my side
    Last edited by MadMatLoco; 03-24-2023 at 04:31 AM. Reason: Solved

  13. #13
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Run time error 91 on datas

    Apologies for late response...Had an urgent matter to attend to...Yes, solved here too...
    Sub TRANSFERT()
    Dim WsP As Worksheet, WsM As Worksheet, debut As Date, fin As Date
    Set WsP = Sheets("PARAMS"): Set WsM = Sheets("MARKETS")
    debut = WsP.Range("F11").Value
    Set trouver1 = WsM.[R:R].Find(debut, , xlFormulas, xlWhole)
    If Not trouver1 Is Nothing Then adresse1 = trouver1.Row
    fin = WsP.Range("K11").Value
    Set trouver2 = WsM.[R:R].Find(fin, , xlFormulas, xlWhole)
    If Not trouver2 Is Nothing Then adresse2 = trouver2.Row
    End Sub

  14. #14
    Registered User
    Join Date
    03-23-2023
    Location
    Paris
    MS-Off Ver
    365
    Posts
    8

    Re: Run time error 91 on datas

    Hope all is fine

    Thanks a lot

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Code runs in small datas but not working perfectly in bigger datas
    By RAJESH SHAH in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-04-2021, 10:28 PM
  2. compare oracle table datas and excel datas
    By james94539 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-01-2013, 03:48 PM
  3. Cross post >> Error on extracting datas from Pivottable with VBA
    By eloa in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-29-2007, 07:41 AM
  4. Time-Datas to Time-Bars
    By tinastar in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-21-2006, 04:28 AM
  5. Transformation of Time-Datas
    By tinastar in forum Excel General
    Replies: 0
    Last Post: 09-21-2006, 04:25 AM
  6. sort certain datas in a wide range of datas
    By go4cdt in forum Excel General
    Replies: 2
    Last Post: 03-20-2006, 12:45 PM
  7. re : Finding the datas and deleting datas which are not found.
    By ddiicc in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-30-2005, 09:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1