+ Reply to Thread
Results 1 to 5 of 5

Update Logic - Clear Contents & Cell Value Formatting

Hybrid View

  1. #1
    Valued Forum Contributor Parth007's Avatar
    Join Date
    12-01-2014
    Location
    Banglore
    MS-Off Ver
    2010
    Posts
    879

    Update Logic - Clear Contents & Cell Value Formatting

    Hello Friends..

    Can anyone please assist me in below Point 1 & pont 2..

    I tried everything but not getting a correct code to run..

    Point 1) Below is the code which helps to clear values from Cells of columns AA, AB & AC if Cells of Column Vis Null or empty


    Sub POINT1()
    
    
    Dim i As Long
    
    With ThisWorkbook.Worksheets("RESULTS")
    
     For i = 2 To .Range("A" & .Rows.Count).End(xlUp).Row
            If .Range("V" & i).Value <> vbNullString Or .Range("V" & i).Value = "" Then
                 If InStr(1, .Range("V" & i).Value, "RUM", vbTextCompare) = 0 Then
                    .Range("AA" & i).ClearContents
                    .Range("AB" & i).ClearContents
                    .Range("AC" & i).ClearContents
                End If
            End If
        Next
    
    End With
    
    End Sub
    The problem here is that i am data of more than 50,000 & the above code takes around 30-45 minutes to execute or sometime crash or sometime no response


    Point 2) This below code copies the cell data from column 25 & paste it in column 26 if the cell is blank in column 26.. but after copying it is converting the date as date (
    attached is the file for reference..
    The data in Column Z cells marked in yellow shows data as year 2017.. but according to Column V its 2016 year.. example (RUM122316-070725-49)
    How can we change or update the code .. please suggest

    
    Sub POINT2()
    
    Dim NR As Long
    With ThisWorkbook.Worksheets("RESULTS")
    ActiveSheet.Range("Y:Y").Select
        With Selection
        .NumberFormat = "0"
        End With
    
        
        ActiveSheet.Range("Y2").Select
        NR = .Range("A" & .Rows.Count).End(xlUp).Row
        Range("Y2:Y" & NR).Formula = "=CONCATENATE(MID(V2,4,2),""/"",MID(V2,6,2))"
    
    
    Dim i As Long
    Dim LTR As Long
    
        With ThisWorkbook.Worksheets("RESULTS")
    LTR = .Range("A" & .Rows.Count).End(xlUp).Row
            For i = 2 To LTR
            If .Range("Z" & i).Value = vbNullString Or .Range("Z" & i).Value = "" Then
            Cells(i, 26).Value = Cells(i, 25).Value
            Cells(i, 26).Font.ColorIndex = 5
           
            End If
        Next
            Range("Z2:Z" & NR).Value = Range("Z2:Z" & NR).Value
        End With
        End With
    
    End Sub
    Last edited by Parth007; 01-04-2017 at 02:58 AM.
    Regards
    Parth

    I appreciate your feedback. Hit * if u Like.
    Rules - http://www.excelforum.com/forum-rule...rum-rules.html

  2. #2
    Valued Forum Contributor Parth007's Avatar
    Join Date
    12-01-2014
    Location
    Banglore
    MS-Off Ver
    2010
    Posts
    879

    Re: Update Logic - Clear Contents & Cell Value Formatting

    Hello Experts please suggest/ assist a better code for Poiint1 & Point 2

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Update Logic - Clear Contents & Cell Value Formatting

    Hello Parth007,

    The code shown for Point 1 is 3 times faster on the sample workbook and will be much faster on a larger data set.

    As for Point 2, the abbreviated date method displaying the the month and day less the year, mm/dd, only works with the current year. You cannot use this format with dates that are not the current year. You will have to display the date in mm/dd/yy format.

    Point 1 Macro Code
    Sub POINT_1()
    
        Dim Cell As Range
        Dim i    As Long
        
            With ThisWorkbook.Worksheets("RESULTS")
                For i = 2 To .Range("A" & .Rows.Count).End(xlUp).Row
                    Set Cell = .Cells(i, "V")
                    If Len(Cell) > 0 Then
                        If InStr(1, Cell, "RUM", vbTextCompare) > 0 Then
                            Cell.Offset(0, 5).Resize(1, 3).Value = Empty
                        End If
                    End If
                Next i
            End With
        
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Update Logic - Clear Contents & Cell Value Formatting

    Hello Parth007,

    The code shown for Point 1 is 3 times faster on the sample workbook and will be much faster on a larger data set.

    As for Point 2, the abbreviated date method displaying the the month and day less the year, mm/dd, only works with the current year. You cannot use this format with dates that are not the current year. You will have to display the date in mm/dd/yy format.

    Point 1 Macro Code
    Sub POINT_1()
    
        Dim Cell As Range
        Dim i    As Long
        
            With ThisWorkbook.Worksheets("RESULTS")
                For i = 2 To .Range("A" & .Rows.Count).End(xlUp).Row
                    Set Cell = .Cells(i, "V")
                    If Len(Cell) > 0 Then
                        If InStr(1, Cell, "RUM", vbTextCompare) > 0 Then
                            Cell.Offset(0, 5).Resize(1, 3).Value = Empty
                        End If
                    End If
                Next i
            End With
        
    End Sub

  5. #5
    Valued Forum Contributor Parth007's Avatar
    Join Date
    12-01-2014
    Location
    Banglore
    MS-Off Ver
    2010
    Posts
    879

    Re: Update Logic - Clear Contents & Cell Value Formatting

    hi Ross,

    The Code for Point 1 WORKED... I HAVE CHANGED THE '<' & '>' to '='

    Sub POINT_1()
    
        Dim Cell As Range
        Dim i    As Long
        
            With ThisWorkbook.Worksheets("RESULTS")
                For i = 2 To .Range("A" & .Rows.Count).End(xlUp).Row
                    Set Cell = .Cells(i, "V")
                    If Len(Cell) = 0 Then
                        If InStr(1, Cell, "RUM", vbTextCompare) = 0 Then
                            Cell.Offset(0, 5).Resize(1, 3).Value = Empty
                        End If
                    End If
                Next i
            End With
        
    End Sub

    Please assist me if the changes I have done is correct
    Last edited by Parth007; 01-03-2017 at 03:25 AM.

+ 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] Needing VBA code to clear contents of cell when the contents of another cell is cleared
    By jeh0714 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-15-2016, 03:49 PM
  2. Clear merged cell contents in comand button(clear all)
    By mohan_984 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-25-2015, 10:39 AM
  3. clear contents of cell based on column value/update continuously
    By forWork1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-01-2015, 12:34 PM
  4. Clear Contents of a cell if contents = 1/0/00
    By superiorsvc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-03-2015, 06:25 PM
  5. Validation value cell update logic
    By shelby_335 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-08-2015, 08:21 PM
  6. [SOLVED] Clear contents based on contents of another cell
    By Katrina DTE in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-13-2013, 02:44 PM
  7. Clear Contents on Update when other code exists in the Worksheet_Change thingy
    By JRS_ in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-09-2011, 12:11 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