Closed Thread
Results 1 to 3 of 3

Please help me with this code ...i dont understand

Hybrid View

  1. #1
    Registered User
    Join Date
    07-05-2011
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    3

    Please help me with this code ...i dont understand

    The task to do :

    Col A Col D

    100 4
    101 2
    102 4
    105 2
    100 1
    101 2
    102 3
    1055 1

    After my code is run, I need for my spreadsheet to look like this

    Col A Col D
    100 5
    101 4
    102 7
    105 2

    And there was one guy post his solution code below :

    
    Sub Test()
    
        Dim Sh As Worksheet
        Dim LastRow As Long
        Dim Rng As Range
        Set Sh = Worksheets(1)
        Sh.Columns(5).Insert
    
        LastRow = Sh.Range("A65536").End(xlUp).Row
        With Sh.Range("A1:A" & LastRow).Offset(0, 4)
            .FormulaR1C1 = "=IF(COUNTIF(R1C[-4]:RC[-4],RC[-4])>1,"""",SUMIF(R1C[-4]:R[" &      LastRow & "]C[-4],RC[-4],R1C[-1]:R[" & LastRow & "]C[-1]))"
            .Value = .Value
        End With
    
        Sh.Columns(4).Delete
        Sh.Rows(1).Insert
        Set Rng = Sh.Range("D1:D" & LastRow + 1)
    
        With Rng
            .AutoFilter Field:=1, Criteria1:="="
            .SpecialCells(xlCellTypeVisible).EntireRow.Delete
        End With
    
    End Sub
    Now , based on this code, i have too much confusions:

    1: why did he insert column 5?
    2, how to understand the COUNTIF systax ?? What is [-1] etc
    3,what did he mean for deleting column5, and insert Row (1)??
    4,why did he use autofilter?

    i am sorry for my confusions, this code is realy awsome, just want to know how does it work,,, because i am a noob now....

    Many thanks for any help !!!!!!!!!!!!
    Last edited by umliu37; 07-06-2011 at 10:48 AM. Reason: Added Code Tags

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Please help me with this code ...i dont understand

    Hi umliu37

    Welcome to the Forum....

    Please wrap your code in code tags, before the moderators get you...

    Click here - Forum rules
    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # button at the top of the post window. If you are editing an existing post, press Go Advanced to see the # button.
    Cheers

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Please help me with this code ...i dont understand

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

    PLEASE PM WHEN YOU HAVE DONE THIS AND I WILL DELETE THIS POST
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

Closed 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