+ Reply to Thread
Results 1 to 8 of 8

Simplify code INDEX ROWS COUNTA

Hybrid View

  1. #1
    Registered User
    Join Date
    03-07-2014
    Location
    london
    MS-Off Ver
    Excel 2016
    Posts
    83

    Simplify code INDEX ROWS COUNTA

    HI all

    I have the following code

    1. How can i simplify it . (it is basically merging data from columns, im repeating the same code for different column ranges)

    2. For range O6:O355 & Q6:Q355 i would like the following format mmm-yy


    Sub site_assumptions_calcul_P9_p501_valued()
    
    With Range("M6:M355")
        .Formula = "=IF(B6<>"""",B6,INDEX(H$6:H$355,ROWS(M$6:M6)-COUNTA(B$6:B$355)))&"""""
    '    .Value = .Value
        .Copy
        .PasteSpecial xlPasteValues
    End With
    
    
    With Range("N6:N355")
        .Formula = "=IF(C6<>"""",C6,INDEX(I$6:I$355,ROWS(N$6:N6)-COUNTA(C$6:C$355)))&"""""
    '    .Value = .Value
        .Copy
        .PasteSpecial xlPasteValues
    End With
    
    
    With Range("O6:O355")
        .Formula = "=IF(D6<>"""",D6,INDEX(J$6:J$355,ROWS(O$6:O6)-COUNTA(D$6:D$355)))&"""""
    '    .Value = .Value
        .Copy
        .PasteSpecial xlPasteValues
        
    End With
    
    
    With Range("P6:P355")
        .Formula = "=IF(E6<>"""",E6,INDEX(K$6:K$355,ROWS(P$6:P6)-COUNTA(E$6:E$355)))&"""""
    '    .Value = .Value
        .Copy
        .PasteSpecial xlPasteValues
    End With
    
    
    With Range("Q6:Q355")
        .Formula = "=IF(F6<>"""",F6,INDEX(L$6:L$355,ROWS(Q$6:Q6)-COUNTA(F$6:F$355)))&"""""
    '    .Value = .Value
        .Copy
        .PasteSpecial xlPasteValues
    End With
    many thanks!!!

    Antonio
    Last edited by antonio32; 05-01-2019 at 04:26 AM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Simplify code INDEX ROWS COUNTA

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)

  3. #3
    Registered User
    Join Date
    03-07-2014
    Location
    london
    MS-Off Ver
    Excel 2016
    Posts
    83

    Re: Simplify code INDEX ROWS COUNTA

    Thanks I followed your instructions now , can you help? thanks in advance!

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Simplify code INDEX ROWS COUNTA

    Thanks.

    Your formulae appear to shift across consistently, so this should work:
    With Range("M6:P355")
        .Formula = "=IF(B6<>"""",B6,INDEX(H$6:H$355,ROWS(M$6:M6)-COUNTA(B$6:B$355)))&"""""
        .Value = .Value
    End With
    
    Range("O6:O355").NumberFormat = "mmm-yy"
    Range("Q6:Q355").NumberFormat = "mmm-yy"

  5. #5
    Registered User
    Join Date
    03-07-2014
    Location
    london
    MS-Off Ver
    Excel 2016
    Posts
    83

    Re: Simplify code INDEX ROWS COUNTA

    HI Stephen

    thanks for your answer

    i think your code doesn't take into account the following

    With Range("Q6:Q355")
        .Formula = "=IF(F6<>"""",F6,INDEX(L$6:L$355,ROWS(Q$6:Q6)-COUNTA(F$6:F$355)))&"""""
    '    .Value = .Value
        .Copy
        .PasteSpecial xlPasteValues
    End With

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Simplify code INDEX ROWS COUNTA

    Missed that off the end of your original post. Just change the first line to
    With Range("M6:Q355")

  7. #7
    Registered User
    Join Date
    03-07-2014
    Location
    london
    MS-Off Ver
    Excel 2016
    Posts
    83

    Re: Simplify code INDEX ROWS COUNTA

    many thanks, it is fantastic! works well

  8. #8
    Registered User
    Join Date
    03-07-2014
    Location
    london
    MS-Off Ver
    Excel 2016
    Posts
    83

    Re: Simplify code INDEX ROWS COUNTA

    I'm trying to add IFERROR To the formula but it doesn't work ! can you add IFERROR please? thanks in advance .Antonio

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Index Matching + ranged CountA
    By UHD in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-23-2021, 01:59 PM
  2. Index Matching & CountA function
    By UHD in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-06-2017, 11:08 AM
  3. [SOLVED] Help Simplify Very Basic VBA Code to Delete Non-Adjacent Rows in Excel
    By zfeinstein in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-11-2013, 02:11 PM
  4. [SOLVED] IF & INDEX Formula =INDEX(D11:D59,COUNTA(D11:D59),1)
    By GC1 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-05-2013, 08:11 AM
  5. [SOLVED] How to simplify the VBA code from function to send rows into send range
    By herukuncahyono in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-13-2013, 03:11 AM
  6. [SOLVED] help w/formulas (index, counta, and choose)
    By linksavage in forum Excel General
    Replies: 4
    Last Post: 01-23-2011, 01:37 AM
  7. Simplify Index Function
    By k9mikep in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-02-2010, 01:32 PM

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