Posts by Richie(UK)

    Re: Reduce running time of macro - help appreciated!


    Hi Eric and welcome to the forum (and congratulations on a well-presented first post!).


    You have already identified the common speed-up measures (Screenupdating and Calculation).


    The code could be tidied here and there by assigning some variables to the various objects and using With statements but I'm not sure how much that will help. Have you tried stepping through the code (F8) to try to identify any obvious bottlenecks in execution time? Also, just to give us some context, what size are the worksheets that you are working with (how many rows and columns are currently used)?

    Re: Status Bar


    Where is the variable glb_origCalculationMode declared? How/when is it given a value?


    If you want a percentage figure you will need to know how many files are being processed. I assume that you have a function called GetFileList that is used to populate the fileList Variant variable. Have a look at the Ubound property and use that in combination with my original post (#2) to see if you can figure it out.

    Re: Look at cell value and split file


    Hi,


    I goofed on the Find part, that's why it gave the error. Try the following replacement:


    Re: Status Bar


    Hi,


    You need to actually tell the status bar to display the message. Add the following line after the part where the StatusBarMsg variable is updated.


    Code
    Application.StatusBar = StatusBarMsg

    Re: Look at cell value and split file


    OK, a slight change of approach is needed I think - otherwise we will be adding workbooks into the directory that is being processed and that could cause problems. The amended version below uses a function, courtesy of JWalk, to get an array of file names and then process this rather than looping through the directory.


    Re: Look at cell value and split file


    Hi,


    OK, first draft suggestion below. Please note that I don't have time to test this at the moment. Given that the code includes file deletion I strongly suggest that you work with a dummy directory and dummy workbooks until the code is working as intended - please exercise care. (I have commented out the deletion line in the code below - probably best to leave it like that until everything else is working as intended).


    Re: Status Bar


    Hi and welcome to the firum.


    You could amend something like this to suit your purposes.


    Re: Look at cell value and split file


    Hi and welcome to the forum.


    Is column A in date order or would the worksheet need to be sorted first?
    Is there a set number of columns that is used?
    Are the files to be saved in the same folder as the original files?

    Re: Using sendkeys and loop to download files


    Hi,


    How about a slight re-hash of the last part (lCount as a Long variable):


    Code
    Set inputCollection = ieDoc.getElementsByTagName("download")
         
        lCount = 0
        For Each inputElement In inputCollection
            lCount = lCount + 1
            If inputElement.getAttribute("value") = "Download" And lCount = 4 Then
                inputElement.Click
                Exit For
            End If
        Next inputElement


    If that doesn't work could you persuade your IT guys to set-up an example page for us to work with - identical to the one that you are accessing but with any sensitive data replaced by dummy text files?

    Re: Need to automate goal seek with VBA


    Hi and welcome to the forum.


    You may need to tinker with this as I couldn't immediately see how you planned to increment the capex but it should help get you started.


    Re: Opening files using cell values


    Hi and welcome to the forum.


    Caveats: Not tested and no error-checking. Should get you started though.


    Re: Loop to run calculation on every row with data


    Hi and welcome to the forum.


    Wouldn't it be simpler to write functions for each of the calculations to be undertaken (TPO, PMVval, and N)? You can then just apply the function to as many rows as needed, as you would for a standard Excel function.

    Re: Autofilter Block Of Data From Activecells Offset


    Sorry, missed that bit. Doh!


    Code
    Sub OrToePhilTar()
        Dim rngAF As Range
         
        Set rngAF = Range(ActiveCell.Offset(-1, 1), ActiveCell.Offset(2, 4))
        rngAF.AutoFilter
        rngAF.Columns(4).Sort Key1:=ActiveCell.Offset(0, 4), Order1:=xlAscending, Header:=xlGuess, _
            OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
            
    End Sub

    Re: How to find minimum value in every row VBA


    Something like this?


    Code
    Sub test()
        Dim lRowEnd As Long
        
        With Worksheets("Sheet1")
            lRowEnd = .Cells(.Rows.Count, "O").End(xlUp).Row
            .Range("P4").FormulaR1C1 = "=MIN(RC[-3]:RC[-1])"
            .Range("P4").AutoFill Destination:=Range("P4:P" & lRowEnd)
        End With
        
    End Sub

    Re: How to find minimum value in every row VBA


    Hi and welcome to the forum.
    Any particular reason for wanting a VBA approach? If you really want the VBA approach how about using the Macro Recorder while you type in the appropriate formula? You can then tidy it up to suit your needs.

    Re: Loop through visible rows only.


    Hi,


    The SpecialCells method is indeed the way to go here. Specifically you want to make use of the xlCellTypeVisible type. This, as the name suggests, applies to all visible cells (ie it will exclude those that do not fit the filter criteria). So, we apply our filter and then set a range that is equal to the filtered range as modified by the SpecialCells method. We can then loop through this non-contiguous range if we wish. See below for a simple example.