+ Reply to Thread
Results 1 to 4 of 4

Macro to (i) drag and drop & (ii) input array formula

  1. #1
    Registered User
    Join Date
    12-11-2008
    Location
    Southern California
    Posts
    13

    Question Macro to (i) drag and drop & (ii) input array formula

    Hi,

    I need help writing macros to do the following specific functions:

    1) I have a program from which I can retrieve data and export the data as an Excel spreadsheet. Now, based on the search parameters I use in the program, the data to be exported into Excel has the same number of columns, but the number of rows can differ. I need a macro to work on any spreadsheet, independent of how many rows of data that spreadsheet may have. And this macro needs to do the following:

    Suppose the spreadsheet when initially retrieved has 4 columns worth of data. I input a column between A and B, so now the spreadsheet's applicable columns are A-N-B-C-D, where N represents New column. I need to populate N with values, but these values are a function of column A. Now, I have already created a macro that (i) creates N and (ii) populates the first non-header cell in N (N2) with a value that is a function of cell A2. What I need is a macro to populate cells N3-Nx, based on the values in cells A2-Ax, where x is the number of rows for which there is data in column A. This macro will replace me having to manually drag the formula in cell B2 all the way down to cell Bx. Once again, this macro needs to work regardless of how many rows of data are in a spreadsheet.

    2) The second macro involves me inputting a complicated multiple-sum array formula into a cell. This formula has multiple "if" statements, and also references other sheets in the workbook. It does not reference other workbooks. I tried the record method. I pressed record, typed in the formula, but then when I pressed enter, I got a "Could Not Record" message. So I copied the formula into Word, and then pressed record in Excel, pasted the formula from Word into the Excel cell, but then when I went to convert it into an array by pressing F2 and Ctrl+Shift+Enter, I got the "Could Not Record" message again. Is there a macro that will let me input such an array formula into a specific cell on the designated sheet?

    Thanks in advance for your help. I hope I have explained clearly what I need to macros to do.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    1) Having put in the formula into B2 do
    Please Login or Register  to view this content.
    2) If you can put the formula directly into the cell and it works OK, then should be able to do it with code. Can you give us the formula and the range it would have to cover. Is it array entered across the entire range, or array entered into a single cell and copied across the range.


    rylo

  3. #3
    Registered User
    Join Date
    12-11-2008
    Location
    Southern California
    Posts
    13
    Rylo,

    1) Your code worked perfectly! Thanks.

    2) Here is the formula. The idea is for me to input this formula into one cell, and drag it across all the applicable cells. The necessary row and column designations would change with the drag. The formula would apply from cell B11 to cell E77. Here is the formula. Its huge:

    =IF($A44="N/A","N/A",IF($A44="Preshow",IF($E$4="All",SUM('Total Show'!I$2:I$65536*('Total Show'!$B$2:$B$65536="S")*('Total Show'!$F$2:$F$65536<$E$2)),SUM('Total Show'!I$2:I$65536*('Total Show'!$B$2:$B$65536="S")*('Total Show'!$F$2:$F$65536<$E$2)*('Total Show'!$D$2:$D$65536=$E$4))),IF($A44="Postshow",IF($E$4="All",SUM('Total Show'!I$2:I$65536*('Total Show'!$B$2:$B$65536="S")*('Total Show'!$F$2:$F$65536>$E$3)),SUM('Total Show'!I$2:I$65536*('Total Show'!$B$2:$B$65536="S")*('Total Show'!$F$2:$F$65536>$E$3)*('Total Show'!$D$2:$D$65536=$E$4))),IF($E$4="All",SUM('Total Show'!I$2:I$65536*('Total Show'!$B$2:$B$65536="S")*('Total Show'!$F$2:$F$65536=$A44)),SUM('Total Show'!I$2:I$65536*('Total Show'!$B$2:$B$65536="S")*('Total Show'!$F$2:$F$65536=$A44)*('Total Show'!$D$2:$D$65536=$E$4))))))
    The formula is supposed to go in a sheet titled "Hours Summary", and it links a sheet in the same workbook titled "Total Show". There are many formulas for summing using multiple conditions, for example:

    SUM('Total Show'!I$2:I$65536*('Total Show'!$B$2:$B$65536="S")*('Total Show'!$F$2:$F$65536<$E$2)*('Total Show'!$D$2:$D$65536=$E$4))
    These formulas are array formulas, which is why that large formula needs to be made into an array via Ctrl+Shift+Enter after it is inputted into cell B11. Then, after the formula in cell B11 is made an array, I want to drag it over the range B11:E77.

    Hope this makes sense.

    Thanks so much for your help.
    Last edited by JHCali; 12-11-2008 at 04:08 AM.

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    The reason the macro recording is falling over is that the formula is too long. I can't get it to array enter directly from code either.

    A couple of options
    1) Somehow make the formula smaller
    2) Have code put the formula in as text without the "=". The cell will take the string, but not as a formula.

    If you take 2, then you would have to manually edit the formula, add the "-", then array enter. Filling the range could either be done manually or with code (but only after the formula entry).

    HTH

    rylo

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1