+ Reply to Thread
Results 1 to 16 of 16

Code running very slow

Hybrid View

scavia Code running very slow 03-12-2023, 08:58 AM
Mumps1 Re: Code running very slow 03-12-2023, 11:26 AM
Marc L Re: Code running very slow 03-12-2023, 11:33 AM
scavia Re: Code running very slow 03-12-2023, 12:05 PM
Mumps1 Re: Code running very slow 03-12-2023, 12:17 PM
scavia Re: Code running very slow 03-12-2023, 12:30 PM
Mumps1 Re: Code running very slow 03-12-2023, 12:43 PM
Marc L Re: Code running very slow 03-12-2023, 01:19 PM
scavia Re: Code running very slow 03-12-2023, 12:56 PM
scavia Re: Code running very slow 03-12-2023, 01:27 PM
TMS Re: Code running very slow 03-12-2023, 01:31 PM
scavia Re: Code running very slow 03-12-2023, 01:48 PM
Mumps1 Re: Code running very slow 03-12-2023, 01:55 PM
scavia Re: Code running very slow 03-12-2023, 01:59 PM
scavia Re: Code running very slow 03-12-2023, 04:31 PM
Mumps1 Re: Code running very slow 03-12-2023, 04:33 PM
  1. #1
    Registered User
    Join Date
    05-08-2020
    Location
    Pennsylvania, USA
    MS-Off Ver
    2016
    Posts
    35

    Code running very slow

    I am running the below code to read data from several files, find key properties and write them to a Sheet. There are 54 very long files (e.g., 12,000 lines), but I don't think this should run so slow. I've identified the section of code below that I think is slowing it down. I hope someone can help me figure this out.

    Option Explicit
    
    Sub ExtractLatLng()
        Dim MyFolder As String, MyFile As String, textline As String, x As Workbook
        Dim r As Integer, pos As Integer, JJ As Integer, JJJ As Integer, JK As Integer
        Dim File As String, Depth As String, Sensor As Integer, Hit As Integer
        Dim Combo As String, DepthIncrement As Double, StationDepth As Double
        Dim J As Integer, test As String, iyear As String, YearCheck As Double, SampleDate As Double, DateTest As Double
        Dim Station As String, PreviousSampleDate As Double
        Dim MyFileName As String
        Dim name0 As String
        Dim CruiseDate As String
        Dim NewDepth As String
        Dim LastDepth As String
        Dim iFn As Integer
        Dim strFilename As String, NewFilename As String
        Dim strFileContent As String
        Dim v As Variant
        Dim i As Integer
        Dim wb As Workbook
        Dim sh As Worksheet
        Dim arrCount  As Integer
        Dim ub As Integer
    
    'Application.ScreenUpdating = False
    Worksheets("sheet1").Cells.ClearContents
    
    
    Worksheets("Sheet1").Cells(1, 1).Value = "Station"
    Worksheets("Sheet1").Cells(1, 2).Value = "Sample Date"
    Worksheets("Sheet1").Cells(1, 3).Value = "Cruise Date"
    Worksheets("Sheet1").Cells(1, 4).Value = "DO"
    Worksheets("Sheet1").Cells(1, 5).Value = "Station Depth"
    Worksheets("Sheet1").Cells(1, 6).Value = "Sample Depth"
    Worksheets("Sheet1").Cells(1, 7).Value = "Sensor Code"
    Worksheets("Sheet1").Cells(1, 9).Value = "File Name"
    Worksheets("Sheet1").Cells(3, 12).Value = "Running"
    
    J = 1
    YearCheck = DateValue(Worksheets("Sheet2").Cells(10, 11))
    ' Loop through all stations and dates
    Do While J < 54
    iyear = Worksheets("Sheet2").Cells(6, 11)
    DepthIncrement = Worksheets("Sheet2").Cells(8, 11)
    Worksheets("sheet3").Cells.ClearContents
    
    
    'Rewrite GLNPO data inversing bottom to top in Sheet4
                MyFolder = "C:\Users\scavia\Dropbox (University of Michigan)\Box Sync\Current Folders\Papers, Proposals, & Talks\In Prep\Hypoxia model\GLNPO DO\" & iyear & "\"
                File = Worksheets("Sheet2").Cells(J, 1)
                MyFile = Dir(MyFolder & File)
                strFilename = (MyFolder & File)
                 iFn = FreeFile
                 Open strFilename For Input As #iFn
                 strFileContent = Input(LOF(iFn), iFn)
                 Close #iFn
                 v = Split(strFileContent, vbCrLf)
                 JK = 0
                 JJ = UBound(v)
                 ub = UBound(v) - 1
                 For i = ub To 1 Step -1
                    JK = JK + 1
                    Worksheets("sheet3").Cells(JK, 1).Value = v(i)
                  Next i
    ' End rewriting
    
    ' Create File Path
    MyFolder = "C:\Users\scavia\Dropbox (University of Michigan)\Box Sync\Current Folders\Papers, Proposals, & Talks\In Prep\Hypoxia model\GLNPO DO\2012\"
    File = Worksheets("Sheet2").Cells(J, 1)
    MyFile = Dir(MyFolder & File)
    pos = InStr(File, "ER")
    Station = Mid(File, pos, 4)
    ' Indentify depth used to look for BWDO
    DepthIncrement = 1
    If Station = "ER30" Then StationDepth = 20.7
    If Station = "ER31" Then StationDepth = 21.7
    If Station = "ER32" Then StationDepth = 22.2
    If Station = "ER36" Then StationDepth = 22.9
    If Station = "ER37" Then StationDepth = 23.6
    If Station = "ER38" Then StationDepth = 21.7
    If Station = "ER42" Then StationDepth = 22
    If Station = "ER43" Then StationDepth = 21.9
    If Station = "ER73" Then StationDepth = 23.8
    If Station = "ER78" Then StationDepth = 22.7
    
    If Station = "ER30" Then Depth = StationDepth - DepthIncrement
    If Station = "ER31" Then Depth = StationDepth - DepthIncrement
    If Station = "ER32" Then Depth = StationDepth - DepthIncrement
    If Station = "ER36" Then Depth = StationDepth - DepthIncrement
    If Station = "ER37" Then Depth = StationDepth - DepthIncrement
    If Station = "ER38" Then Depth = StationDepth - DepthIncrement
    If Station = "ER42" Then Depth = StationDepth - DepthIncrement
    If Station = "ER43" Then Depth = StationDepth - DepthIncrement
    If Station = "ER73" Then Depth = StationDepth - DepthIncrement
    If Station = "ER78" Then Depth = StationDepth - DepthIncrement
    
    r = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row + 1
    
    Hit = 0
    
    
    ' Loop through lines of text
                JJJ = 0
                Do While JJJ < JJ
                JJJ = JJJ + 1
                Worksheets("Sheet1").Cells(2, 12) = JJJ
    
    
    'Get textline from upside down data in Sheet4
               textline = Worksheets("sheet3").Cells(JJJ, 1)
    
    ' THIS IS LIKELY THE SLOW PART
               
    ' Look in each file for Cruise date and Depth
                         pos = InStr(textline, Depth)
                         If Hit = 0 And pos = 6 Then
                                test = Mid(textline, 57, 5)
                                If test = "" Then Sensor = 1
                                Worksheets("Sheet1").Cells(J + 1, 1).Value = Station                                                                                 '  Write Startion in column 1
                                Worksheets("Sheet1").Cells(J + 1, 9) = File                                                                                                '  Write FileName in column 9
                                Worksheets("Sheet1").Cells(J + 1, 5).Value = StationDepth                                                                       '  Write Station Depth in column 5
                                Worksheets("Sheet1").Cells(J + 1, 6).Value = Mid(textline, pos, 5)                                                           '  Write Sample Depth in column 6
                                If Sensor = 1 Then
                                          Worksheets("Sheet1").Cells(J + 1, 4).Value = Mid(textline, pos + 21, 5)                                            '  Write DO in column 4
                                Else
                                          Worksheets("Sheet1").Cells(J + 1, 4).Value = Mid(textline, pos + 30, 5)                                            '  Write  DO in column 4
                                End If
                                Hit = 1
                            Else
                                   pos = InStr(textline, "System UpLoad Time = ")
                                   If pos > 0 Then
                                        Worksheets("Sheet1").Cells(J + 1, 2).Value = DateValue(Mid(textline, pos + 21, 12))                          'Write Sample Date in column 2
                                            SampleDate = DateValue(Mid(textline, pos + 21, 12))
                                            DateTest = YearCheck - SampleDate                                                                                                    'Compare Sample Date and Cruise Date
                                            If Abs(DateTest) < 5 Then
                                                     CruiseDate = PreviousSampleDate
                                             '        PreviousSampleDate = SampleDate
                                             Else
                                                     CruiseDate = SampleDate
                                                     YearCheck = SampleDate
                                                     PreviousSampleDate = SampleDate
                                             End If
                                        Worksheets("Sheet1").Cells(J + 1, 3).Value = CruiseDate                                                                   'Write Cruise Date in column 3
                                        Worksheets("Sheet1").Cells(J + 1, 7) = Sensor                                                                                        ' Write sensor code in column 7
                                    Exit Do
                                    Else
                                    End If
                            End If
                             r = r + 1
                     Loop
    J = J + 1
                 
    Loop
    
    Application.ScreenUpdating = True
    MsgBox ("DONE")
    End Sub

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,024

    Re: Code running very slow

    You are using a lot of looping which will slow the macro down considerably. I can't promise a solution, but it would be easier to help and test possible solutions if you could attach a copy of your destination file and at least one of your source files. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary). See the yellow banner at the top of this page for instructions to attach a file.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Code running very slow


    As Slow is the Excel surname ! Better is to use any database software …

    Anyway do not forget to set ScreenUpdating to False before writting to cells ! (codeline in comment, why ?‼)

  4. #4
    Registered User
    Join Date
    05-08-2020
    Location
    Pennsylvania, USA
    MS-Off Ver
    2016
    Posts
    35

    Re: Code running very slow

    Thanks. I added more comments to the code and include an example of one of the source files. Basically, I first reverse the order of rows in the source file and put the results in Sheet3.
    Then for each file listed in Sheet2, I examine each row to look for specific threads in the text. When I find one that I am looking for, I write parts of that line to Sheet1.
    The input files were given to me in .CNV format, which looks like text lines in an Excel sheet. When I try to upload one of the files (or even a portion of one),
    I get a message saying it is invalid. So, below the code, I have included enough lines from the file to show what they look like. I hope that helps some.
    Option Explicit
    
    Sub ExtractLatLng()
        Dim MyFolder As String, MyFile As String, textline As String, x As Workbook
        Dim r As Integer, pos As Integer, JJ As Integer, JJJ As Integer, JK As Integer
        Dim File As String, Depth As String, Sensor As Integer, Hit As Integer
        Dim Combo As String, DepthIncrement As Double, StationDepth As Double
        Dim J As Integer, test As String, iyear As String, YearCheck As Double, SampleDate As Double, DateTest As Double
        Dim Station As String, PreviousSampleDate As Double
        Dim MyFileName As String, ENDline As Integer
        Dim name0 As String
        Dim CruiseDate As String
        Dim NewDepth As String
        Dim LastDepth As String
        Dim iFn As Integer
        Dim strFilename As String, NewFilename As String
        Dim strFileContent As String
        Dim v As Variant
        Dim i As Integer
        Dim wb As Workbook
        Dim sh As Worksheet
        Dim arrCount  As Integer
        Dim ub As Integer
    
    'Application.ScreenUpdating = False
    Worksheets("sheet1").Cells.ClearContents
    
    
    Worksheets("Sheet1").Cells(1, 1).Value = "Station"
    Worksheets("Sheet1").Cells(1, 2).Value = "Sample Date"
    Worksheets("Sheet1").Cells(1, 3).Value = "Cruise Date"
    Worksheets("Sheet1").Cells(1, 4).Value = "DO"
    Worksheets("Sheet1").Cells(1, 5).Value = "Station Depth"
    Worksheets("Sheet1").Cells(1, 6).Value = "Sample Depth"
    Worksheets("Sheet1").Cells(1, 7).Value = "Sensor Code"
    Worksheets("Sheet1").Cells(1, 9).Value = "File Name"
    Worksheets("Sheet1").Cells(3, 12).Value = "Running"
    
    J = 1
    YearCheck = DateValue(Worksheets("Sheet2").Cells(10, 11))
    
    
    
    Do While J < 25
    iyear = Worksheets("Sheet2").Cells(6, 11)
    DepthIncrement = Worksheets("Sheet2").Cells(8, 11)
    Worksheets("sheet3").Cells.ClearContents
    
    ' My source file below (MyFile) has to have the rows altered so it reads last line to first line.
    'The code below takes data from MyFile and reverses the order in Sheet3
    'Rewrite GLNPO data inversing bottom to top in Sheet3
                MyFolder = "C:\Users\scavia\Dropbox (University of Michigan)\Box Sync\Current Folders\Papers, Proposals, & Talks\In Prep\Hypoxia model\GLNPO DO\" & iyear & "\"
                File = Worksheets("Sheet2").Cells(J, 1)
                MyFile = Dir(MyFolder & File)
                strFilename = (MyFolder & File)
                 iFn = FreeFile
                 Open strFilename For Input As #iFn
                 strFileContent = Input(LOF(iFn), iFn)
                 Close #iFn
                 v = Split(strFileContent, vbCrLf)
                 JK = 0
                 JJ = UBound(v)           ' number of rows in Sheet3
                 ub = UBound(v) - 1
                 For i = ub To 1 Step -1
                    JK = JK + 1
                    Worksheets("sheet3").Cells(JK, 1).Value = v(i)
                     Next i
    ' End rewriting
    
    ' Here are my source files (a copy is attached)
    ' Create File Path
    MyFolder = "C:\Users\scavia\Dropbox (University of Michigan)\Box Sync\Current Folders\Papers, Proposals, & Talks\In Prep\Hypoxia model\GLNPO DO\2012\"
    File = Worksheets("Sheet2").Cells(J, 1)
    MyFile = Dir(MyFolder & File)
    pos = InStr(File, "ER")
    Station = Mid(File, pos, 4)
    
    ' Here's were indentify a specfic depth to look for depending on the source file
    ' At the first occurance of that depth, I access data from that row
    DepthIncrement = 1
    If Station = "ER30" Then StationDepth = 20.7
    If Station = "ER31" Then StationDepth = 21.7
    If Station = "ER32" Then StationDepth = 22.2
    If Station = "ER36" Then StationDepth = 22.9
    If Station = "ER37" Then StationDepth = 23.6
    If Station = "ER38" Then StationDepth = 21.7
    If Station = "ER42" Then StationDepth = 22
    If Station = "ER43" Then StationDepth = 21.9
    If Station = "ER73" Then StationDepth = 23.8
    If Station = "ER78" Then StationDepth = 22.7
    
    If Station = "ER30" Then Depth = StationDepth - DepthIncrement
    If Station = "ER31" Then Depth = StationDepth - DepthIncrement
    If Station = "ER32" Then Depth = StationDepth - DepthIncrement
    If Station = "ER36" Then Depth = StationDepth - DepthIncrement
    If Station = "ER37" Then Depth = StationDepth - DepthIncrement
    If Station = "ER38" Then Depth = StationDepth - DepthIncrement
    If Station = "ER42" Then Depth = StationDepth - DepthIncrement
    If Station = "ER43" Then Depth = StationDepth - DepthIncrement
    If Station = "ER73" Then Depth = StationDepth - DepthIncrement
    If Station = "ER78" Then Depth = StationDepth - DepthIncrement
    
    r = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row + 1
    
    Hit = 0
    
    
    ' Loop through all of the rows in Sheet3.
                JJJ = 0
                Do While JJJ < JJ
                JJJ = JJJ + 1
                Worksheets("Sheet1").Cells(2, 12) = JJJ   ' Just a counter
    
    
    'Get textline from Sheet3
               textline = Worksheets("sheet3").Cells(JJJ, 1)
    
               
                 ' Look in row for Cruise date and Depth. When found, write to Sheet1
                         pos = InStr(textline, Depth)
                         If Hit = 0 And pos = 6 Then
                                test = Mid(textline, 57, 5)
                                If test = "" Then Sensor = 1
                                Worksheets("Sheet1").Cells(J + 1, 1).Value = Station                                                                                 '  Write Startion in column 1
                                Worksheets("Sheet1").Cells(J + 1, 9) = File                                                                                                '  Write FileName in column 9
                                Worksheets("Sheet1").Cells(J + 1, 5).Value = StationDepth                                                                        '  Write Station Depth in column 5
                                Worksheets("Sheet1").Cells(J + 1, 6).Value = Mid(textline, pos, 5)                                                            '  Write Sample Depth in column 6
                                    If Sensor = 1 Then
                                          Worksheets("Sheet1").Cells(J + 1, 4).Value = Mid(textline, pos + 21, 5)                                            '  Write DO in column 4
                                    Else
                                          Worksheets("Sheet1").Cells(J + 1, 4).Value = Mid(textline, pos + 30, 5)                                            '  Write  DO in column 4
                                    End If
                                    Hit = 1
                            Else
                            End If
                    'Loo in row for Sampling Time when found, write to Sheet2
                            pos = InStr(textline, "System UpLoad Time = ")
                            If pos > 0 Then
                                  Worksheets("Sheet1").Cells(J + 1, 2).Value = DateValue(Mid(textline, pos + 21, 12))                          'Write Sample Date in column 2
                                   SampleDate = DateValue(Mid(textline, pos + 21, 12))
                                    DateTest = YearCheck - SampleDate                                                                                                    'Compare Sample Date and Cruise Date
                                         If Abs(DateTest) < 5 Then
                                                  CruiseDate = PreviousSampleDate
                                         Else
                                                   CruiseDate = SampleDate
                                                     YearCheck = SampleDate
                                                     PreviousSampleDate = SampleDate
                                          End If
                                    Worksheets("Sheet1").Cells(J + 1, 3).Value = CruiseDate                                                                   'Write Cruise Date in column 3
                                    Worksheets("Sheet1").Cells(J + 1, 7) = Sensor                                                                                        ' Write sensor code in column 7
                                    Exit Do
                               Else
                               End If
                      '     End If
                           r = r + 1
                     Loop
    J = J + 1
                 
    Loop
    
    Application.ScreenUpdating = True
    MsgBox ("DONE")
    End Sub
    THIS IS WHAT THE INPUT FILES LOOK LIKE
    * Sea-Bird SBE25 Data File:
    * FileName = \\LGDC01\01_MT_Data\01_Sensor_Data\SBE25\2012\Erie Do July 17\July 17 DO -All casts separated by cast-004.hex
    * Software Version 1.59
    * Temperature SN = 031554
    * Conductivity SN = 042244
    * System UpLoad Time = Sep 20 2012 15:52:00
    ** Lake Erie DO July 17 2012
    ** All casts separated by cast (cast 4)
    * ds
    * SBE 25 CTD V 4.0b SN 111 09/20/12 11:39:41.012
    * external pressure sensor, range = 1000 psia, tcval = 181
    * xtal = 9437443 clk = 32768.342 vmain = 12.6 iop = 170 vlith = 5.4
    * ncasts = 15 samples = 30246 free = 74216 lwait = 0 msec
    *
    * CTD configuration:
    * number of scans averaged = 1, data stored at 8 scans per second
    * real time data transmitted at 8 scans per second
    * minimum conductivity frequency for pump turn on = 2644
    * pump delay = 30 seconds
    *
    * battery type = ALKALINE
    *
    * 1 external voltages sampled
    * stored voltage # 0 = external voltage 0
    *

    * S>
    * dh
    * cast 4 07/25 08:32:33 smpls 6924 to 10404 nv = 1 avg = 1 stp = switch of

    * S>
    # nquan = 4
    # nvalues = 3481
    # units = specified
    # name 0 = depFM: Depth [fresh water, m]
    # name 1 = t090C: Temperature [ITS-90, deg C]
    # name 2 = sbeox0Mg/L: Oxygen, SBE 43 [mg/l]
    # name 3 = flag: 0.000e+00
    # span 0 = -0.636, 23.395
    # span 1 = 13.2216, 25.8660
    # span 2 = 1.61425, 9.09414
    # span 3 = 0.0000e+00, 0.0000e+00
    # interval = seconds: 0.125
    # start_time = Jul 25 2012 08:32:33 [Instrument's time stamp, header]
    # bad_flag = -9.990e-29
    # <Sensors count="4" >
    # <sensor Channel="1" >
    # <!-- Frequency 0, Temperature -->
    # <TemperatureSensor SensorID="55" >
    # <SerialNumber>031554</SerialNumber>
    # <CalibrationDate>25-Jan-12</CalibrationDate>
    # <UseG_J>1</UseG_J>
    # <A>0.00000000e+000</A>
    # <B>0.00000000e+000</B>
    # <C>0.00000000e+000</C>
    # <D>0.00000000e+000</D>
    # <F0_Old>0.000</F0_Old>
    # <G>4.85050923e-003</G>
    # <H>6.81902510e-004</H>
    # <I>2.74285429e-005</I>
    # <J>2.21584767e-006</J>
    # <F0>1000.000</F0>
    # <Slope>1.00000000</Slope>
    # <Offset>0.0000</Offset>
    # </TemperatureSensor>
    # </sensor>
    # <sensor Channel="2" >
    # <!-- Frequency 1, Conductivity -->
    # <ConductivitySensor SensorID="3" >
    # <SerialNumber>042244</SerialNumber>
    # <CalibrationDate>17-Jan-12</CalibrationDate>
    # <UseG_J>1</UseG_J>
    # <!-- Cell const and series R are applicable only for wide range sensors. -->
    # <SeriesR>0.0000</SeriesR>
    # <CellConst>2000.0000</CellConst>
    # <ConductivityType>0</ConductivityType>
    # <Coefficients equation="0" >
    # <A>0.00000000e+000</A>
    # <B>0.00000000e+000</B>
    # <C>0.00000000e+000</C>
    # <D>0.00000000e+000</D>
    # <M>0.0</M>
    # <CPcor>-9.57000000e-008</CPcor>
    # </Coefficients>
    # <Coefficients equation="1" >
    # <G>-1.02770178e+001</G>
    # <H>1.47451413e+000</H>
    # <I>-6.23325241e-004</I>
    # <J>1.23463596e-004</J>
    # <Tcor>0.0000</Tcor>
    # </OxygenSensor>
    # </sensor>
    # </Sensors>
    # datcnv_date = Sep 27 2012 14:00:44, 7.21f [datcnv_vars = 3]
    # datcnv_in = C:\EPAWork\Lake Erie DO\Erie DO\Erie 12\July 17-18\ER36 7-25 (25).hex C:\EPAWork\Lake Erie DO\Erie DO\Erie 12\July 17-18\SBE 25 060512.xmlcon
    # datcnv_skipover = 0
    # datcnv_ox_hysteresis_correction = yes
    # datcnv_ox_tau_correction = yes
    # file_type = ascii
    *END*
    -0.539 25.7811 8.23811 0.000e+00
    -0.539 25.7744 8.24493 0.000e+00
    -0.636 25.7666 8.24674 0.000e+00
    -0.636 25.7616 8.24812 0.000e+00
    -0.636 25.7612 8.24869 0.000e+00
    -0.636 25.7572 8.24972 0.000e+00
    -0.636 25.7522 8.25079 0.000e+00
    -0.636 25.7486 8.25155 0.000e+00
    -0.636 25.7468 8.25193 0.000e+00
    -0.636 25.7450 8.24640 0.000e+00
    -0.636 25.7401 8.25213 0.000e+00
    -0.636 25.7347 8.24705 0.000e+00
    -0.636 25.7339 8.25206 0.000e+00
    -0.636 25.7339 8.25186 0.000e+00
    -0.636 25.7318 8.25188 0.000e+00

  5. #5
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,024

    Re: Code running very slow

    I'm afraid that without having access to the actual files (destination and source), it would be hard see how the data is actually organized. Is it not possible to attach copies of the Excel files?

  6. #6
    Registered User
    Join Date
    05-08-2020
    Location
    Pennsylvania, USA
    MS-Off Ver
    2016
    Posts
    35

    Re: Code running very slow

    It would not allow me to upload a .CNV file so I opened and saved it as .xlsx it is now attached

    Thanks
    Attached Files Attached Files

  7. #7
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,024

    Re: Code running very slow

    Thank you for the file. Could you please also attach a copy of the destination file which includes Sheet 1 to 3 with the data represented by the variables YearCheck, iyear and DepthIncrement?

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Code running very slow


    Quote Originally Posted by scavia View Post
    It would not allow me to upload a .CNV file so I opened and saved it as .xlsx
    Well, well, well ! As it is very not difficult to rename a couple of source text files as .txt !
    For example File1.cnv as File1.cnv.txt and File2.cnv as File2.cnv.txt then attach both in this thread …

  9. #9
    Registered User
    Join Date
    05-08-2020
    Location
    Pennsylvania, USA
    MS-Off Ver
    2016
    Posts
    35

    Re: Code running very slow

    Here is the .xlxm file with all of the information. Sorry this is problematic. I am not very experienced with VBA!
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    05-08-2020
    Location
    Pennsylvania, USA
    MS-Off Ver
    2016
    Posts
    35

    Re: Code running very slow

    I just tried that again. Opened file.cnv and saved as file.cnv.txt. When I tried to upload it, it said "upload of file failed". So, I renamed file.cnv.txt to file.txt
    and that failed too. Strange.

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,017

    Re: Code running very slow

    Try creating a zip file with all the samples you need, .cnv, .xlsx, .xlsm, and upload the zip file.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  12. #12
    Registered User
    Join Date
    05-08-2020
    Location
    Pennsylvania, USA
    MS-Off Ver
    2016
    Posts
    35

    Re: Code running very slow

    Tried using 7-zip which is on my PC. the file.7z upload also failed. Maybe I'm just wasting your time now?

  13. #13
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,024

    Re: Code running very slow

    For clarification:
    You want to open the files listed in column A of Sheet2 in the Extract DO file. Then you want to reverse the order of Sheet1 of the opened file to Sheet 3 of the Extract DO file. Is this correct?

  14. #14
    Registered User
    Join Date
    05-08-2020
    Location
    Pennsylvania, USA
    MS-Off Ver
    2016
    Posts
    35

    Re: Code running very slow

    Yes, I want to do that before looking at the individual rows because the order matters

  15. #15
    Registered User
    Join Date
    05-08-2020
    Location
    Pennsylvania, USA
    MS-Off Ver
    2016
    Posts
    35

    Re: Code running very slow

    Mumps1 - I wanted to close this loop with you because I found my problem. I was looping inside too many loops as you pointed out in the beginning. I really appreciate the help.

  16. #16
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,024

    Re: Code running very slow

    My pleasure.

+ 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 running very slow
    By nagendra1312 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-22-2021, 04:31 AM
  2. If / Then Code Running Very Slow
    By tswood in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 09-11-2019, 02:38 AM
  3. Slow running Code
    By Ausadian in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-25-2015, 04:41 PM
  4. Slow running code
    By phil2006 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-13-2013, 08:02 AM
  5. vba code running too slow
    By hitsujicute in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-31-2013, 06:00 PM
  6. VBA Code running very slow. Need help
    By krjoshi in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-21-2013, 02:13 PM
  7. Code running slow
    By lou031205 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-08-2007, 12:20 PM

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