Posts by stildawn

    Re: VBA to open another workbook, run macros and run macros in it?


    Thanks for the above, I have got it working thanks, however I now run into a "Run Time Error 7: Out of Memory"


    Is there a fix for this? Here is the full code that I am using, and start by running the "run" macro from workbook book1.


    Cheers


    Hi All


    I have a master template excel file, for which I copy in various other data from other works and then run corresponding macros depending on the data I pasted in.


    The issue I have now, is that I have a source workbook that has multiple sheets in it, so in order to make it work in the master template I would need to copy in each of these multiple sheets before running the macros, which is time consuming as you can imagine.


    So I was thinking I could code it so I run a macro in the master template file which opens this the source workbook, runs some macros and returns the now formatted data for further processing.


    Heres what I have so far which is full of holes I imagine:



    Its pretty raw at the moment, but you get the idea.


    Is this possible as its not working for me so far... Also is there away to get a open file window to pop up instead so the user could just navigate to the source workbook?


    Thanks in advance

    Hi All


    I do a dump of emails from outlook into excel, mainly for counting purposes. The issue I have is that depending on the date of the emails this is how they come into excel:


    [TABLE="width: 500"]

    [tr]


    [td]

    Date

    [/td]


    [/tr]


    [tr]


    [td]

    Mon 24/06

    [/td]


    [/tr]


    [tr]


    [td]

    Sun 23/06

    [/td]


    [/tr]


    [tr]


    [td]

    22/06/13

    [/td]


    [/tr]


    [tr]


    [td]

    21/06/13

    [/td]


    [/tr]


    [tr]


    [td]

    20/06/13

    [/td]


    [/tr]


    [/TABLE]



    The issue is that I just need them as a month and year format, also the "Mon 24/06" type is not recognised as a date by Excel, while the "21/06/13" type are recognised as dates, so I have used formatting options on the "21/06/13" type and they change correctly, but if you do date formatting on the "Mon 24/06" types nothing happens.


    So I guess I have two questions:


    1. In VBA how to turn "Mon 24/06" into a date format, so I can then do:
    2. In VBA turn "21/06/13" date format into just "06/13"


    So this:
    [TABLE="width: 500"]

    [tr]


    [td]

    Date

    [/td]


    [/tr]


    [tr]


    [td]

    Mon 24/06

    [/td]


    [/tr]


    [tr]


    [td]

    Sun 23/06

    [/td]


    [/tr]


    [tr]


    [td]

    22/06/13

    [/td]


    [/tr]


    [tr]


    [td]

    21/06/13

    [/td]


    [/tr]


    [tr]


    [td]

    20/06/13

    [/td]


    [/tr]


    [/TABLE]


    Turns into this:[TABLE="width: 500"]

    [tr]


    [td]

    Date

    [/td]


    [/tr]


    [tr]


    [td]

    24/06/13

    [/td]


    [/tr]


    [tr]


    [td]

    23/06/13

    [/td]


    [/tr]


    [tr]


    [td]

    22/06/13

    [/td]


    [/tr]


    [tr]


    [td]

    21/06/13

    [/td]


    [/tr]


    [tr]


    [td]

    20/06/13

    [/td]


    [/tr]


    [/TABLE]


    Which turns into this:[TABLE="width: 500"]

    [tr]


    [td]

    Date

    [/td]


    [/tr]


    [tr]


    [td]

    06/13

    [/td]


    [/tr]


    [tr]


    [td]

    06/13

    [/td]


    [/tr]


    [tr]


    [td]

    06/13

    [/td]


    [/tr]


    [tr]


    [td]

    06/13

    [/td]


    [/tr]


    [tr]


    [td]

    06/13

    [/td]


    [/tr]


    [/TABLE]




    Thanks in advance for any help.


    Cheers

    Re: VBA - Add formula to reference another workbook


    Hi All


    By taking a different approach I have fixed it with this code:


    Re: Macro


    This should work.


    Re: Help with this Formula/Code


    Quote from Oracle2057;670586

    Hello stildawn,


    If column A always has the actual cell location within the other workbook you are trying to reference then use the code below.


    Code
    link = "=INDIRECT(""[" & Filename & "]" & sh & "!"" & RC[-1])"


    I tried this and it comes back with a #REF! error in the cells, with this formula in them:


    =INDIRECT("[20130516_XX_IR_Uploadfinal_V1.0_12062013.xls]AFR_TYPE1!" & A2)


    ??

    Re: Help with this Formula/Code


    Quote from cytop;670160

    You can only edit the title for a certain time after posting - post your revised title in a reply here and I'll update it for you.


    What would you suggest? Help with VBA Formula to reference another workbook?




    Quote from jindon;670122


    Um this looks a bit complicated for what I am trying to do, where would I put this code.


    The: link = "=[" & Filename & "]" & sh & "!RC[-1]"


    Seems to almost work, at least it actually puts something in the cells instead of erroring like my old code didl. However the RC[-1] is not getting the cell value like it usually does? But is returning the cell location instead. I just need to put the value of the cell to the left at the end of the formula?

    Formula code for linking into another workbook?


    Thanks for the reply.


    I did the above, however this makes the formula this:


    =[book1.xls]Sheet1!A1
    =[book1.xls]Sheet1!A2
    =[book1.xls]Sheet1!A3
    =[book1.xls]Sheet1!A4


    etc


    It seems the RC[-1] part of the link formula just puts that actual cells reference to the left in, it doesn't put in the cell value to the left?


    For example in this workbook its now looks like this:


    [TABLE="width: 500"]

    [tr]


    [td][/td]


    [td]

    Column A

    [/td]


    [td]

    Column B

    [/td]


    [/tr]


    [tr]


    [td]

    1

    [/td]


    [td]

    Sheet1

    [/td]


    [td][/td]


    [/tr]


    [tr]


    [td]

    2

    [/td]


    [td]

    J545

    [/td]


    [td]

    =[book1.xls]Sheet1!A2

    [/td]


    [/tr]


    [tr]


    [td]

    3

    [/td]


    [td]

    J214

    [/td]


    [td]

    =[book1.xls]Sheet1!A3

    [/td]


    [/tr]


    [tr]


    [td]

    4

    [/td]


    [td]

    J457

    [/td]


    [td]

    =[book1.xls]Sheet1!A4

    [/td]


    [/tr]


    [tr]


    [td]

    5

    [/td]


    [td]

    J547

    [/td]


    [td]

    =[book1.xls]Sheet1!A5

    [/td]


    [/tr]


    [/TABLE]



    But I want it to look like this:


    [TABLE="width: 500"]

    [tr]


    [td][/td]


    [td]

    Column A

    [/td]


    [td]

    Column B

    [/td]


    [/tr]


    [tr]


    [td]

    1

    [/td]


    [td]

    Sheet1

    [/td]


    [td][/td]


    [/tr]


    [tr]


    [td]

    2

    [/td]


    [td]

    J545

    [/td]


    [td]

    =[book1.xls]Sheet1!J545

    [/td]


    [/tr]


    [tr]


    [td]

    3

    [/td]


    [td]

    J214

    [/td]


    [td]

    =[book1.xls]Sheet1!J214

    [/td]


    [/tr]


    [tr]


    [td]

    4

    [/td]


    [td]

    J457

    [/td]


    [td]

    =[book1.xls]Sheet1!457

    [/td]


    [/tr]


    [tr]


    [td]

    5

    [/td]


    [td]

    J547

    [/td]


    [td]

    =[book1.xls]Sheet1!547

    [/td]


    [/tr]


    [/TABLE]




    So the formula looks up the cell reference in A (the value of A cells J545 etc). In the other workbook (book1.xls in this example) under the sheet at the top of the list in column A (Sheet1).


    Thanks

    Hi All


    I believe this is the last piece of the puzzle of a project I'm working on. Here are the components I have to work with:


    Component 1:

    Code
    Dim file As Range
    Set file = Range("rgFileToBeChecked")
    
    
    'this sets "file" as the full path


    or


    Code
    Dim fso As New FileSystemObject
    Dim fileName As String
    fileName = fso.GetFileName(file)
    
    
    'this turns "file" from full path into "fileName" which is just the actual file name


    For example file = C:\test\test1\test.xlsm


    or


    fileName = text.xlsm


    Component 2:

    Code
    Dim sh As String
    sh = Cells(1,col)


    This returns a sheet name, so sh could = sheet1, or whatever the sheet name is.


    Component 3:

    Code
    INDIRECT(""RC[-1]"",0)


    This just refers to the cell to the left of the cell the code is working on. This will return a cell reference for example E21, A50 etc. (E21, A50 etc are the values in the cells to the left)





    So I need to just put all these 3 components together to get a working formula that simply looks up a cell reference on a specific sheet on another workbook.


    I will then be putting this formula in via ActiveCell = whatever formula we come up with


    I just don't know how to string it all together, but I'm sure it will be something like:


    "=" & file & sh & "INDIRECT(""RC[-1]"",0)"


    Which would be in an example something like:


    =C:\Test\Test2\Test.xlsm Sheet1 E50 - So the result of the formula needs to be E50 on sheet1 on test.xlsm? Just can't seem to figure out what random characters I need inbetween or whatever to make it work.


    Thanks in advance.




    Heres the full code of what I am doing if anyone needs it:


    Re: Excel Userform Combobox Properties Rowsource box issues?


    Quote from royUK;669493

    Look at using ThisWorkBook


    Code
    ComboBox1.RowSource = ThisWorkBook.Sheets("Sheet1").Range("a4:a5").Value



    Unfortunately I tried the that also. As far as I can tell I did the code right.


    The only thing I can think of is that the userform initializes wrong because I have this code as well:



    This turns on the userform and hides excel as soon as the file opens, I'm wondering maybe its bypassing the userform_initialize event? (By the way I know that its not userform_initialize, I have it as FilterNames_Initialize)


    My other idea is am I ment to put anything into the rowsource box in properties when using VBA code to populate the rowsource? Cause I just deleted it and left it blank when I tried the code populating method?


    Thanks

    I have a userform in Excel that works as a calculator.


    In this userform I have two ComboBoxs (1 & 2)


    In VBA editor, with ComboBox1 selected, In Properties, under Rowsourse I have: Sheet1!a4:a5


    In Sheet1, A4 = Auckland and A5 = Christchurch


    This is fine and when I run the userform there is a drop down arrow with the two options (Auckland or Christchurch).
    However my problem is that when you open this workbook I have a VBA command to hide it from the users sight, leaving them only the userform to work with which is what is desired.


    The issue is that if you have another workbook open then open this calculator workbook (which automatically hides itself). Then the combobox list is populated by Sheet1!a4:a5 on the other workbook that was already open, not the workbook that actually contains "Auckland" & "Christchurch" from which the userform is from.


    I have tried making the Rowsource for the comboboxes more specific by putting the following in the rowsource box in properties: [book1.xlsm]sheet1!a4:a5 but this comes up with a "Invalid Property Value" error message.


    I have also tried making a:


    Code
    Private Sub Userform1_Initialize()
    
    
    ComboBox1.Additem "Auckland"
    ComboBox1.Additem "Christchurch"
    
    
    End Sub


    And also tried this:


    Code
    Private Sub Userform1_Initialize()
    
    
    ComboBox1.RowSource = Workbooks("book1.xlsm").Sheets("Sheet1").Range("a4:a5").Value
    
    
    End Sub


    However with both codes when it opens and runs now the comboboxes are empty and there is no list.


    I think the easist solution would be to somehow put the full path (including workbook name) into the rowsource box under properties. But I must be missing something as its coming up with that error for me?


    All help would be greatly appreciated.


    Thanks