Posts by stildawn

    Re: More Efficient Way To Code This - Hiding Rows Based On User Input


    Would that increase performance considerably?


    I was thinking that its doing the code every time the cursor moves, maybe there is a way or a replacement to "Private Sub Worksheet_SelectionChange(ByVal Target As Range)" that stops running the code all the time, once the fields checked (e.g. E16) have been moved past or something?

    Hi All


    I have made up a form in Excel (not a userform) it has a bunch of drop down boxes etc for users to make certain selections, based on these selections more or less information is required from the user.


    I have this code below, which captures the users selections and expands or subtracts the sheet (hiding rows) to generate what they need.


    Its getting a bit laggy, so I ask how would you awesome vba gurus make this code more efficient and less laggy:


    Re: combine two codes


    Yeah the if is redundant in this case cause the sheet will never be HSK as your looking for the current date haha. Guessing you got the code elsewhere on the net? Its easy to get code but not the context if you know what I mean.


    Happy to help :)

    Re: combine two codes


    I was meaning in the open procedure something like:


    Code
    Private Sub Workbook_Open()
        Dim wsName As String 
         wsName = Format(Date, "dd-mm-yyyy") 
         Worksheets("HSK").Move before:=Sheet(wsName)
         Worksheets(wsName).Activate 
    End Sub


    Since the name will never be "HSK" since you are looking for a date named sheet, you don't need the IF Not block

    Hi All


    I have a register of customers with an expiry date column, basically I have designed code that will check the dates and send emails, records the date this happens and saves, this is working fine.


    The issue I have is that this excel file needs to be opened using windows Task Scheduler each day to process and create/send these emails, however at the same time the user herself would occasionally need to open the file (without running my VBA code) and add new customers, amend data etc and save.


    So I need an idea on how to code for this in the Workbook_Open() sub. So that the file can be opened by task scheduler and automatically run the vba code without any user imput at all. But at the same time the user can open the file without the code running.


    I had initially thought of a Activeworkbook.readonly = true check using a VBS script for the task scheduler to open the file as read only, while the user would just open it normally.


    However both the user and the code needs to save the workbook, so I cant use this readonly method.


    Is there a way for excel to know "how" the file was opened? Like via shortcut or something maybe?


    Thanks in advance

    Hi all


    I have a massive list of data. Which is invoices generated for jobs.


    In column A, is a number that is unique per "job" a few columns over is a few value columns for costs.


    This is generated automatically by a separate system. What I need to do is have some VBA code to tally all the various cost figures (all separate invoices) for each "job" into a total and delete the other invoices.


    Here is a real quick example:


    [TABLE="class: grid, width: 500"]

    [tr]


    [td][/td]


    [td]

    A

    [/td]


    [td]

    B

    [/td]


    [td]

    C

    [/td]


    [/tr]


    [tr]


    [td]

    1

    [/td]


    [td]

    Job Number

    [/td]


    [td]

    Cost of Freight

    [/td]


    [td]

    Cost of Services

    [/td]


    [/tr]


    [tr]


    [td]

    2

    [/td]


    [td]

    6BH555

    [/td]


    [td]

    60

    [/td]


    [td]

    60

    [/td]


    [/tr]


    [tr]


    [td]

    3

    [/td]


    [td]

    7BH666

    [/td]


    [td]

    70

    [/td]


    [td]

    70

    [/td]


    [/tr]


    [tr]


    [td]

    4

    [/td]


    [td]

    6BH555

    [/td]


    [td]

    60

    [/td]


    [td]

    60

    [/td]


    [/tr]


    [tr]


    [td]

    5

    [/td]


    [td]

    8BH777

    [/td]


    [td]

    80

    [/td]


    [td]

    80

    [/td]


    [/tr]


    [tr]


    [td]

    6

    [/td]


    [td]

    7BH666

    [/td]


    [td]

    70

    [/td]


    [td]

    70

    [/td]


    [/tr]


    [tr]


    [td]

    7

    [/td]


    [td]

    8BH777

    [/td]


    [td]

    80

    [/td]


    [td]

    80

    [/td]


    [/tr]


    [/TABLE]


    So here we have three unique job numbers, which have 2 invoices each (they could have many invoices, or there could only be one in the real data)


    I need code that would turn this into:


    [TABLE="class: grid, width: 500"]

    [tr]


    [td][/td]


    [td]

    A

    [/td]


    [td]

    B

    [/td]


    [td]

    C

    [/td]


    [/tr]


    [tr]


    [td]

    1

    [/td]


    [td]

    Job Number

    [/td]


    [td]

    Cost of Freight

    [/td]


    [td]

    Cost of Service

    [/td]


    [/tr]


    [tr]


    [td]

    2

    [/td]


    [td]

    6BH555

    [/td]


    [td]

    120

    [/td]


    [td]

    120

    [/td]


    [/tr]


    [tr]


    [td]

    3

    [/td]


    [td]

    7BH666

    [/td]


    [td]

    140

    [/td]


    [td]

    140

    [/td]


    [/tr]


    [tr]


    [td]

    4

    [/td]


    [td]

    8BH777

    [/td]


    [td]

    160

    [/td]


    [td]

    160

    [/td]


    [/tr]


    [/TABLE]


    As you can see the invoices are tallied together to get a total for the job numbers.


    This is what I need but on a mass scale, and of course all the cost values etc are different, there could by many invoices per job, or there could just be one line in which case nothing would need to be tallied.


    I know I could code this myself, but it would be a very long winded way as I am coming up blank with efficient ideas on how I would do this.


    So any ideas on how to do this efficiently.


    Cheers

    Hi All


    So I have raw reports, which users then run through a Excel tool I have created. The tool does a bunch of stuff to the raw report and then does the following:



    As you can see this saves a clean excel file, I do this to exclude all of the VBA code from the tool so that the newly created report is clean and doesn't prompt the user for anything.


    With this clean report, the user then goes in and adds come data into some cells, based on what the tool has done and their investigation into the reason etc.


    Eventually a monthly report is run, which opens all these daily reports (with in a date range) and does some KPI stuff. This is all good.


    My issue is, that the monthly report needs the "dd-mm-yy" in the file and for the daily files to be in one folder in order to grab the right ones. But since the users need to be able to open these daily reports and make changes, I don't think they can be trusted to keep the file naming and location consistent.


    So I'm thinking, is there away in the code above, to add a "before_close" vba command in the newly created daily report, that simply always saves a copy (and overwrites) correctly into a specific folder, without the user knowing its going on, so the user can rename the file and location as many times as they want, but each time the close it, its still saved correctly elsewhere (with the updates they have done etc).


    I think if this code was just saved into the VBA or the original "Siemens Exception Report - dd-mm-yy.xlsm" then it should work behind the scenes forever right?



    Obviously I would be creating the "CreatedDate" range value in the original saving so that it stays static no matter what day the user works on the file.


    But how do I get just this code into the new clear file.


    Thanks

    Hi All


    I have this code:


    Code
    IniName = "Siemens Exception Report - " & Format(Now, "dd.mm.yy")
        
        savepath = Application.GetSaveAsFilename(InitialFileName:=IniName, FileFilter:="Excel (*.xlsx),FilterIndex:=*.xlsx")


    However when I step through the code and the saveas dialog comes up, the initial file name is always blank instead of having "Siemens Exception Report - 24.07.14" like its ment to.


    I need the dialog box cause the users might want to name it something else, but I need the IniName as a suggestion/in case they don't rename it.

    Re: Runtime Error 16 - Expression too complex


    It is very odd, checking that valid data was available was one of the first things I checked, but it is.


    After mucking around and googling I have solved it kind of.


    By setting the dates into a variable first it solves it so:


    Code
    Diff1 = CDate(.Range("U" & CurRow)) - CDate(.Range("T" & CurRow)) 'Received the error here
    Diff2 = CDate(.Range("V" & CurRow)) - CDate(.Range("U" & CurRow)) 'Stepping to here it also errors
    Diff3 = CDate(.Range("W" & CurRow)) - CDate(.Range("V" & CurRow)) 'And here


    Becomes:


    Code
    D1 = .Range("U" & CurRow)
    D2 = .Range("T" & CurRow)
    Diff1 = CDate(D1) - CDate(D2) 'Received the error here
    D1 = .Range("V" & CurRow)
    D2 = .Range("U" & CurRow)
    Diff2 = CDate(D1) - CDate(D2) 'Stepping to here it also errors
    D1 = .Range("W" & CurRow)
    D2 = .Range("V" & CurRow)
    Diff3 = CDate(D1) - CDate(D2) 'And here


    And for some unknown reason this solves the problem.

    Re: Runtime Error 16 - Expression too complex


    CurRow is a global variable which is populated by a loop that is happening in some Userform code.


    In the test runs, CurRow is working correctly.


    The date value is a date and time value in the cells like "02/07/14 10:00" etc