+ Reply to Thread
Results 1 to 5 of 5

Deleting part of a column without deleting whole rows.

Hybrid View

  1. #1
    Registered User
    Join Date
    01-08-2013
    Location
    Concord, NC
    MS-Off Ver
    Excel 2007
    Posts
    5

    Deleting part of a column without deleting whole rows.

    I have an Automated report...I have A Name in A3 and a decimal time in B3 and that run as long as 300 names. SO list one is in A:B, List 2 is C:D, and List 3 is E:F, Each list has a different set of valid info...

    For List one

    Column B>11 is valid and should be kept <11 is a trash the for that row A:B should be cleared,
    Column D>31is valid and should be kept <31is a trash and for that row C:D should be cleared,
    Column f>11 is valid and should be kept <11 is a trash the for that row E:F should be cleared,

    I can't delete since I cannot disrupt the other 2 lists. My Columns will be drastically uneven but it is what I need.

    (The typical length of the Idol None list with the applied validation is usually about 165 agents, Th Idol Break is usually 70 agents, and Idle_system is usually less than 5 but since there are 300 seats I copied my formula to Row 300)

    I have been lurking here and googling the code to do this but only find code that will delete the entire row. Is there a Macro for me?

    Thanks in Advance!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Deleting part of a column without deleting whole rows.

    Sorry, I did not understand, attach a new file with current and desired table, highlight the cells to be cleared
    If solved remember to mark Thread as solved

  3. #3
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Deleting part of a column without deleting whole rows.

    something like

    Public Sub RemoveInvalidListEntries()
         '#
         '# declare private variables
         '#
              Dim lngListRow As Long
              Dim lngTargetRow As Long
         '#
         '# for the active worksheet
         '#
              With ActiveSheet
              '#
              '# list 1: remove invalid entries
              '#
                   lngTargetRow = 1
                   For lngListRow = 2 To .Cells(.Rows.Count, "B").End(xlUp).Row
                        If Val(.Cells(lngListRow, "B").Value) >= 11 Then
                             lngTargetRow = lngTargetRow + 1
                             If lngTargetRow <> lngListRow Then
                                  .Cells(lngTargetRow, "A").Value = .Cells(lngListRow, "A").Value
                                  .Cells(lngTargetRow, "B").Value = .Cells(lngListRow, "B").Value
                             End If
                        Else
                             .Cells(lngListRow, "A").Value = vbNullString
                             .Cells(lngListRow, "B").Value = vbNullString
                        End If
                   Next lngListRow
              '#
              '# list 2: remove invalid entries
              '#
                   lngTargetRow = 1
                   For lngListRow = 2 To .Cells(.Rows.Count, "D").End(xlUp).Row
                        If Val(.Cells(lngListRow, "D").Value) >= 31 Then
                             lngTargetRow = lngTargetRow + 1
                             If lngTargetRow <> lngListRow Then
                                  .Cells(lngTargetRow, "C").Value = .Cells(lngListRow, "C").Value
                                  .Cells(lngTargetRow, "D").Value = .Cells(lngListRow, "D").Value
                             End If
                        Else
                             .Cells(lngListRow, "C").Value = vbNullString
                             .Cells(lngListRow, "D").Value = vbNullString
                        End If
                   Next lngListRow
              '#
              '# list 3: remove invalid entries
              '#
                   lngTargetRow = 1
                   For lngListRow = 2 To .Cells(.Rows.Count, "F").End(xlUp).Row
                        If Val(.Cells(lngListRow, "F").Value) >= 11 Then
                             lngTargetRow = lngTargetRow + 1
                             If lngTargetRow <> lngListRow Then
                                  .Cells(lngTargetRow, "E").Value = .Cells(lngListRow, "E").Value
                                  .Cells(lngTargetRow, "F").Value = .Cells(lngListRow, "F").Value
                             End If
                        Else
                             .Cells(lngListRow, "E").Value = vbNullString
                             .Cells(lngListRow, "F").Value = vbNullString
                        End If
                   Next lngListRow
              End With
         End Sub
    If you like my contribution click the star icon!

  4. #4
    Registered User
    Join Date
    01-08-2013
    Location
    Concord, NC
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Deleting part of a column without deleting whole rows.

    Solved! OllieB, This was perfect and I thank you!
    Last edited by dstrdOne; 01-30-2013 at 12:03 PM.

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Deleting part of a column without deleting whole rows.

    Maybe:

    Sub dstrdOne()
    Dim lr As Long
    Dim rcell As Range
    
    lr = ActiveSheet.UsedRange.Rows.Count
    
    For Each rcell In Range("B2:B" & lr)
    
        If rcell.Value < 11 Then
        
            Range(rcell.Offset(, -1), rcell).ClearContents
            
        End If
        
    Next rcell
    For Each rcell In Range("D2:D" & lr)
    
        If rcell.Value < 31 Then
        
            Range(rcell.Offset(, -1), rcell).ClearContents
            
        End If
        
    Next rcell
    For Each rcell In Range("F2:F" & lr)
    
        If rcell.Value < 11 Then
        
            Range(rcell.Offset(, -1), rcell).ClearContents
            
        End If
        
    Next rcell
    
    End Sub

+ 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