Posts by LeastAction

    Re: Create Popup alert Form without buttons (like outlook desktop alert)


    I noticed you copied the code in two separate places. The code should just be located in modAlert not in Module1. To use the notification in Module1 you would type modAlert.Alert(text,title,seconds).


    What do you mean by not work? Is it erroring?


    Cheers,
    MJ


    EDIT: Try my sample file


    [ATTACH=CONFIG]40384[/ATTACH]

    Re: Maxif, minif and stdevif functions using wildcard


    Hi JamesMunroe,


    Add the following two subroutines to your module, one is for population and one is for sample standard deviation.


    Cheers,
    MJ


    Re: Create Popup alert Form without buttons (like outlook desktop alert)


    Hi udhaya_k,


    I figured it out! Import the following module into your VBE and it will expose a subroutine called Alert (or modAlert.Alert) which has as arguments: (Message,Title,Number of seconds before it disappears).


    If the number of seconds is 0 or missing it will stay on screen until you click OK. This does exactly as you wish, it will pop up on top of any open application and will run in a separate thread than your macro so it will not halt your code at all (except for the slight time it takes to run its code of course).


    [ATTACH=CONFIG]40359[/ATTACH]


    IMPORTANT: In Excel 2002 and newer you will have to explicitly trust access to your VBA Projects. Go to Tools, Macro, Security. Click on the 2nd tab: Trusted Publishers. In the lower left, choose Trust Access to Visual Basic Project. In Excel 2007, Go to Office Icon, Excel Options, Trust Center, Trust Center Settings, Macro Settings, and choose Trust access to the VBA project object model.


    If you have any questions, feel free to ask.[ATTACH=CONFIG]40377[/ATTACH]


    Cheers,
    MJ


    EDIT: Changed subroutine in modAlert as I forgot to do some cleaning up after the code was run, this should fix that. Replace subroutine CreateAlertObject with this:


    Code
    Public Sub CreateAlertObject(sText As String, sTitle As String, lNumSeconds As Long)
            CreateObject("Wscript.Shell").popup sText, lNumSeconds, sTitle, vbSystemModal + 64
            ThisWorkbook.Close False
            Application.Quit
        End Sub


    or use this updated .bas file:


    [ATTACH=CONFIG]40377[/ATTACH]

    Re: Create Popup alert Form without buttons (like outlook desktop alert)


    Hi udhaya_k,


    Well, I've been working on this for a bit now (it's actually quite interesting). I have managed two methods: the first isn't exactly what you want and the second one I am in the process of coding (deceivingly difficult). The first method is this:


    Code
    CreateObject("Wscript.Shell").popup "Hello World!", 3, "Title", vbSystemModal + 64


    The '3' represents how many seconds you want it stay before disappearing. The problem with this is that your code will pause until the popup disappears.


    For the second method I have been attempting to create my own alert with the functionality you described. Essentially what I did was create a modeless userform consisting of just a Label control, in a subroutine I Load the form, pass it variables (such as text, etc...) and then show it. At this point the activation of the form calls a few Windows API that find its window handle and slowly increment its transparency to create the fade in effect. Up to this point everything is golden, now comes the trouble. To create the disappear after N seconds functionality I thought of adding an Application.OnTime event inside the subroutine to Unload the form (which fades it out), this is fine except for this one point:


    Excel is a single threaded application when performing macros or user actions, if a macro is running the user is blocked out and vice versa. So, even though the Application.OnTime is created in a separate thread it's attempting to run the Unload routine in the macro thread and thus has to wait until the initial code has fully completed before unloading the form. I can't seem to find a way to make the OnTime method pause the initial code and take precedence (nor do I think it's possible). The only way I can think of that might work (and I stress might) is to make a COM Interface that when connected to can create the popup on its own thread server side (which can still be local keep in mind).


    I'll give it a try at some point, I can't say how long it will take as I'd have to look at it a bit more first. Hopefully the first method is good enough. If someone is interested in my half finished Userform popup I can post it. Otherwise if you have any question, feel free to ask.


    Cheers,
    MJ

    Re: Create Popup alert Form without buttons (like outlook desktop alert)


    Hi udhaya_k,


    So if I understand correctly you will be running a macro in excel and while it is running you're going to working in some other application. What you want to happen is at certain points in your macro code you want an alert to pop-up somewhere on the screen that does not require feedback from the user (ie will not stop the code from continuing). If possible, would you like it to disappear after some time or not?


    Is this correct?


    Cheers,
    MJ

    Re: Create new Worksheet from List and combine worksheets in different folders


    Hi Chris,


    Paste the following code into a module in a new workbook, hopefully it's what was intended. The code assumes that the folders already exist and it will overwrite any previous file for that student in '\Grade Sheets'. If you have any questions, feel free to ask.


    Cheers,
    MJ


    Re: Vlookup


    Yup, MATCH/INDEX will work... or for a quick and dirty method you can just copy and paste the 'Payee' column to the left of Date.


    Cheers,
    MJ

    Re: Create new Worksheet from List and combine worksheets in different folders


    Hi Chris,


    Just to clarify a few things. Will the entire Gradebook (say sheet1) be copied into each student's spreadsheet or will it be the part of the Gradebook that represents that student's grades? Example workbooks would be very useful in this situation (with names and grades changed obviously =P ).


    Cheers,
    MJ

    Re: MS XLS function to calculate centroid of a polygon


    Hi rcpomp,


    I'm not sure why you're getting negative values in that case, I can't seem to reproduce the situation. If you give me the coordinates you're using that might help. Otherwise, I've updated the code so that it is used as a worksheet function now. It has five possible results:


    '=Centroid(RANGE, "x")' will give the x-coordinate
    '=Centroid(RANGE, "y")' will give the y-coordinate
    '=Centroid(RANGE, "area")' will give the absolute area
    '=Centroid(RANGE, "sarea")' will give the signed area
    '=Centroid(RANGE)' will give the coordinate pair to 3 decimal places


    Hope this helps and if you have any question, feel free to ask.


    Cheers,
    MJ


    Re: If a cell meets a condition, copy that row to another worksheet


    Hi stickyfeet,


    So I've altered the code a bit to make it a little more general and customizable. Firstly to answer your question:


    Quote


    I've been looking at 'lLocation' as this is where it gets the value from the combobox, then trying to work out how/where it determines which column to look at.


    The code was choosing which column to look at on this line:


    Code
    If vData(lRow, 1) = vTestValue Then


    The '1' means it's checking against the first column in vData which is the array created from the data range. Also, lLocation was getting its value from the rightmost character of your combobox because of how the values were hardcoded in, this isn't really necessary as you'll see in the updated code.


    So, I changed the code so that it lets you choose which column you would like to filter on and then dynamically updates the combobox with a unique and somewhat sorted (works kind of odd on text) list of values from that column. The subroutines to create the unique list and sort it are at the bottom (some of my favourites).


    I also changed two more things:

    • Instead of clearing the report beforehand I decided to delete the used rows.
    • The way the data values are tested against the filtering value was changed to convert them both to text beforehand, just incase one is converted to text at some other point while being passed to and from the userform.

    So here's a copy of the code to look at but I changed your Userform a bit to allow for my changes so I'll also include the .frm and .frx files so you can just import it into your spreadsheet. If you have any questions, feel free to ask.


    Cheers,
    MJ


    [ATTACH=CONFIG]40333[/ATTACH]


    Re: MS XLS function to calculate centroid of a polygon


    Hi rcpomp,


    I wasn't sure if you wanted his to be a function or a subroutine. As the code stands you would have to check the codename of the sheet that contains the data, you can find this in the vba editor, under project explorer in your workbook > excel objects. It should be sheet1 or sheet2 etc... Then in my code where it says:


    Code
    Set oWS = Sheet1


    you would change Sheet1 to whatever your sheet codename is. Or you can have the code obtain a reference to the worksheet by its name by replacing that line with:


    Code
    Set oWS = ThisWorkbook.Worksheets("PUT NAME HERE")



    Quote


    - in a cell to the right, entered "=centroid ( " and gave as parameters the cells A2:B5)
    - got error message


    what am i doing wrong?


    A subroutine doesn't run from a function like that, you would need to run the macro either by clicking inside the code in VBA editor and pressing F5 or by going into the Developer Tab and selecting Macros.


    I can turn this into a worksheet function if you like but I would need to know what you would like it to return. For example, there can be two functions (one for x-pos and one for y-pos), it can be an array function, it can return return a string that contains the coordinate pair, (x,y).


    Cheers,
    MJ

    Re: Find Method from userform, run-time error 91 when find returns nothing


    Hi castc468,


    Try this:


    Code
    Private Sub NumberTextBox_AfterUpdate()
        Dim Found As Range
        Set Found = Sheets("Index").Columns(1).Find(What:=NumberTextBox.Value, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False)
        If Not Found Is Nothing Then
            OKOnly = MsgBox("This # is already in use! Please enter another #", vbOKOnly + vbExclamation, "Error")
        Else
            NameTextBox.SetFocus
        End If
    End Sub


    Cheers,
    MJ



    EDIT: Sorry, just realized it should probably not warn you when the field is blank... change this line:


    Code
    If Not Found Is Nothing Then


    To this one:


    Code
    If Not Found Is Nothing And NumberTextBox.Value <> "" Then

    Re: MS XLS function to calculate centroid of a polygon


    Hi rcpomp,


    Paste the following code into a module.


    Make sure to change which sheet oWS refers to, it should point to a sheet with (x,y) coordinates positioned in column A and B something like this:


    [TABLE="class: grid"]

    [tr]


    [td]

    x

    [/td]


    [td]

    y

    [/td]


    [/tr]


    [tr]


    [td]

    1

    [/td]


    [td]

    -1

    [/td]


    [/tr]


    [tr]


    [td]

    2

    [/td]


    [td]

    -14

    [/td]


    [/tr]


    [tr]


    [td]

    10

    [/td]


    [td]

    -10

    [/td]


    [/tr]


    [/TABLE]





    It will put the centroid position to the right of the data. If you have any questions feel free to ask.


    Cheers,
    MJ



    Re: Dynamically fill array with range(a12:a27) use each item in array as part of file


    Hi gerneka,


    The following code should so as you asked.


    Cheers,
    MJ