+ Reply to Thread
Results 1 to 12 of 12

assistance to make a vba code run on a dynamic range

  1. #1
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,086

    assistance to make a vba code run on a dynamic range

    Hi All

    I have a work tab and a summary tab , the summary tab represent the consolidation of columns in green using sumifs

    I recorded a macro how the figures are consolidated from column range S TO U then column AC ON SUMMARY sheet tab as per their respective headers .


    The range is dynamic as it can lead to 10000 rows or more .

    Looking assistance to adjust recorded macro to last data row making it dynamic .

    The active sheet should be the summary tab sheet when code is triggered

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: assistance to make a vba code run on a dynamic range

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 05-08-2017 at 02:53 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,086

    Re: assistance to make a vba code run on a dynamic range

    Hi

    Tried code but when adding a dummy record on work tab , did not give expected results on summary tab which are unique with, the zero in all columns of summary tab on the far right is the original data

    That of yellow given when added a dummy record added

    Could you have look
    Attached Images Attached Images

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool As a starter …


    Hi !

    Start from this :

    PHP Code: 
    Sub Demo1()
         
    Dim F$
             
    "=SUMIFS(WORK!#1#2,WORK!$H$2:$H$#2,$A2,WORK!$I$2:$I$#2,$B2,WORK!$K$2:$K$#2,$C2)"
             
    Replace$(F"#2"Worksheets("WORK").UsedRange.Rows.Count)
        
    With Worksheets("SUMMARY").UsedRange.Rows
            With 
    .Item("2:" & .Count).Columns
                 
    .Item(4).Formula Replace$(F"#1""$S$2:$S$")
                 .
    Item(5).Formula Replace$(F"#1""$T$2:$T$")
                 .
    Item(6).Formula Replace$(F"#1""$U$2:$U$")
                 .
    Item(7).Formula Replace$(F"#1""$V$2:$V$")
                 .
    Item(8).Formula Replace$(F"#1""$AC$2:$AC$")
            
    End With
                 
    .Cells(.Count 14).Resize(, 5).Formula "=SUM(D2:D" & .Count ")"
        
    End With
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 05-09-2017 at 10:20 PM. Reason: optimization …

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: assistance to make a vba code run on a dynamic range

    JEAN1972

    Try
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,086

    Re: As a starter …

    Marc thanks , just a little tuning , if I do not want the formulas to appear in all the cells where .value goes .

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow


    Two ways :

    • After formula, for formulas global range use .Formula = .Value

    • Replace Formula property by Evaluate method, a must see in VBA inner help.

  8. #8
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,086

    Re: assistance to make a vba code run on a dynamic range

    Jindon

    The code works well, a little issue when I add records on data tab, on summary tab it does not adjust the values and totals it shows zero in i all columns.

    What I actually mean , sample data ends at row 58 in sheet work when data are added e.g to row to 60. the code does not expand to row to 60, it remains at row 58 in the formula thus showing zeros in all columns ,

    A little tweak in the code as well sum of the values at end of numerical data .
    Attached Images Attached Images

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: assistance to make a vba code run on a dynamic range

    JEAN1972

    It should update whenever you run the code, so I don't understand how/when you want to run the code.

  10. #10
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,086

    Re: assistance to make a vba code run on a dynamic range

    Hi Jindon

    An insight that applying code those starting with a 0 digits in column A of summary tariff highlighted yellow is removed when code is applied , those codes are extracted from column H of workings tabs .

    Can u have a look
    Attached Files Attached Files

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: assistance to make a vba code run on a dynamic range

    JEAN1972

    It is nothing to do with the code attached.

  12. #12
    Forum Contributor
    Join Date
    02-11-2014
    Location
    mauritius
    MS-Off Ver
    MS365
    Posts
    1,086

    Re: assistance to make a vba code run on a dynamic range

    Hi Jindon

    I figured out that the issue was to format the column to text , so in applying the code , the issue 0 digits did not appear

    thanks for clarification

+ 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. Make a range dynamic for edition!
    By Hellion in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-25-2016, 02:13 PM
  2. [SOLVED] How to amend VBA code to make it more dynamic?
    By The_Snook in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-11-2016, 06:30 PM
  3. [SOLVED] How to make the following code dynamic?
    By Rerock in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-19-2015, 03:55 PM
  4. [SOLVED] HOw to make a chart range dynamic
    By ammartino44 in forum Excel General
    Replies: 7
    Last Post: 09-21-2015, 02:06 PM
  5. Simply VBA code and make it dynamic
    By Rusty315 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-09-2014, 02:49 AM
  6. How should I make a SUMIF w/ dynamic range?
    By jwright650 in forum Excel General
    Replies: 8
    Last Post: 03-21-2014, 06:29 AM
  7. [SOLVED] Make Static code Dynamic
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-05-2012, 11:09 AM

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