Posts by vba_monkey

    Re: VBA - Enter Formula only if Sheet Exists


    I've managed to get it to work now, the PreviousReport workbook needs to be open.


    I dont know why it would need to be open for this function when it can tell there's no sheet there when entering the vlookup and the workbook isnt open but that's Excel for you.


    Thanks for the Help KjBox

    Re: VBA - Enter Formula only if Sheet Exists


    Thank you, I have tried your code and although it runs without error, it is now having the opposite affect to my code in that it is now adding the Vlookup to all tabs regardless of whether there is a corresposnding tab on the target workbook.

    Hello,


    I am trying to write a macro that enters a Vlookup into a cell only if a corresponding tab exists on another workbbok to compare it to. I'm doing this to try to avoid the 'Select Sheet' Dialogue from appearing if there is no corresponding sheet on the other workbook.


    This is what I have so far (the Function comes from here https://stackoverflow.com/ques…if-worksheetwsname-exists)



    The code works in that it doesnt enter a Vlookup if the sheet doesnt exists but it also doesnt recognise if the sheet does exist so I think the issue is with setting the SheetToFind.


    Any ideas please?


    Also posted here https://www.mrexcel.com/forum/…t-exists.html#post4893764
    http://"https://stackoverflow.com/questions/6040164/excel-vba-if-worksheetwsname-exists"



    http://"https://stackoverflow.com/questions/6040164/excel-vba-if-worksheetwsname-exists"

    Re: VBA - Escape Key and Error Handler


    I can get it to work too on a blank sheet so there's obviously something going wrong in my workbook. Here's the full code, I'm not sure you'll be able to test as it involves updating pivot tables that are connect to a network data source.


    I thought it might be this part that is doing it but commenting them out has no effect:


    Code
    Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        Application.EnableEvents = False
        Application.Calculation = xlCalculationManual


    Full code:


    Re: VBA - Escape Key and Error Handler


    Thanks, I've already seen that but it doesnt really answer why my code isnt working as it says it should in that article. I have a Go To statement and EnableCancelKey is set to xlErrorHandler. If Esc is pressed then it goes tp the error handler as it should but then seems to return to xlInterrupt without running through the code in the error handler.

    Hello,


    I am trying to get excel to go to my error handler if Esc is pressed whilst the macro is running. This is what I have so far but when I press Esc, Excel goes to the error handler and breaks on the first line with error 'User interrupt occurred' instead of running through the code in the error handler:



    Any ideas please?



    Also posted here:
    https://www.mrexcel.com/forum/…pe-key-error-handler.html

    Hello,


    This code comes at the end of a macro and is supposed to save the workbook in the correct folder. The folders are labelled Jan, Feb Mar etc. and the file should be saved in the previous months folder so, current month - 1. The codes works but it always saves the workbook in the Jan folder.


    Can anyone see what's wrong?


    Code
    Dim Filepath As String
    
    
    Filepath = "V:\DMU\Split Report Reconciliations\OS Claims\" & Year(Date) & "\" & Format(Month(Date) - 1, "mmm") & "\"
    ActiveWorkbook.SaveAs Filename:=Filepath & Replace(ActiveWorkbook.Name, ".xlsm", "_" & Format(Date, "yyyy") & "_" & Format(Date, "mm") & "_" & Format(Date, "dd") & ".xlsx"), FileFormat:=51


    Thanks

    Hello,


    The point of this code is to insert column B, copy the header from the first cell on the left into B1 and then insert "SJ-" followed by the value in the cell to the left (A2) in B2 down to the bottom of the data.



    The problem is that every cell contains "SJ-" and the value of A2 so the question is, how to make Cells(2, 1) relative so that it always using the value to the left of the cell?

    Hello,


    Can someone please take a look at the attached file to see if you can figure out why the Vlookup in column C is not working? I've tried everything that I can think of like; they are both formatted the same, I've tried copying the data to a different spreadsheet, I've copied it to a text file and back again and I've tried TRIM and CLEAN to see if there was anything invisible that was stopping it from working but no success.


    I've confirmed that the values are presnt in both columns for instance the value in A2 can be found in B1092 using Ctrl-F so, if Excel can find it that why, why cant the Vlookup find it?


    Any ideas please?


    Thanks


    Also posted here:


    https://www.mrexcel.com/forum/…-working.html#post4882356

    Re: VBA - Clearing Selection of Picture


    Not sure why but putting .Activate in causes my vlookupos to either not be entered or deleted. I've tried step through the code and it seems to work but when running on it's own, it does not.


    If it helps, here is the whole of the code i'm running



    I've tried putting this line of code somewhere else in the macro and the result is always the same.

    Hello,


    I have this code which does various things on a worksheet but the issue I'm having is with the last three lines:



    The issue is that once the macro has finished, the logo image that was copied over remains selected which looks untidy so I wanted to unselect it by moving to a different cell which is the purpose of the last line. The problem is that no matter what I try (.Range("C6").Select, Cells("C6").Select, Cells(6, 3).Select etc.) all return the same error 'Select method of Range class failed'


    Application.CutCopyMode = False also has no effect.


    What am I doing wrong?


    Thanks


    This has also been posted here:


    https://www.mrexcel.com/forum/…ng-selection-picture.html

    Hello,


    Can anyone please tell me why the below codes returns the error 'The item could not be found in the OLAP Cude'. The macro stops on the third line of the Else statement when trying to set field filter values, the two lines before it which clear the filters work ok.


    'Year' and 'Month' are both variables selected by the user on a UserForm and I think the issue is getting the variable into the Array().



    It may also be that the variables have been declared as String, I've done it this way as the user has the option of 'All' to select.


    Thanks