+ Reply to Thread
Results 1 to 6 of 6

fix coding

Hybrid View

  1. #1
    Registered User
    Join Date
    12-28-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    54

    fix coding

    Hello,

    Can someone take a look at this coding and tell me why it makes some of the information I'm trying to sort disappear?

    Option Explicit
    
    Sub o2Match_Horses()
    '
    ' o2MatchHorses Macro
    '
    ' Match horses that are highlighted in Column D to the highlighted horses in Column K.
    '
    ' Keyboard Shortcut: Ctrl+Shift+B
    '
      Dim LR As Long
      Dim Rng As Range, cel As Range, c As Range
      Dim ws As Worksheet
    
      Set ws = Sheets("Sheet1")
    
      Application.ScreenUpdating = False
      With ws
        LR = .Range("D" & .Rows.Count).End(xlUp).Row
        Set Rng = .Range(.Cells(1, "D"), .Cells(LR, "D"))
    
        Rng.AutoFilter Field:=1, Operator:=xlFilterNoFill
        .Range(.Cells(2, "L"), .Cells(LR, "L")).SpecialCells(xlCellTypeVisible).Value = "x"
        .AutoFilterMode = False
    
        Set Rng = .Range(.Cells(2, "D"), .Cells(LR, "D"))
        For Each cel In Rng
          'If Not .Cells(cel.Row, "L").Value = "x" Then
            'If Not Trim(cel.Value) = Trim(.Cells(cel.Row, "K").Value) Then
              Set c = .Columns(11).Find(cel.Value, LookIn:=xlValues)
              'If Not c Is Nothing Then
                '.Range(.Cells(cel.Row, "E"), .Cells(cel.Row, "K")).Value = .Range(.Cells(c.Row, "E"), .Cells(c.Row, "K")).Value
              'End If
            'End If
          'End If
        Next cel
        '.Columns(12).ClearContents
      End With
      Application.ScreenUpdating = True
    End Sub
    Attached is a sample you can use to show you what I mean and hopefully fix it to where it doesn't delete information.

    CheerZ!
    Wyldjokre69

    Sample11062014.xlsb

    P.s: the code takes the highlighted horses in Cells D & K and matches them up including the data in Cells E-O. Apply and see for yourself. If you can add a piece of coding which will keep the data that is not highlighted in pink and have it just match across all between E-O, that would be super.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: fix coding

    Is the data that's disappearing the data that's been highlighted using conditional formatting?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    12-28-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    54

    Re: fix coding

    yes, i don't know why though.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: fix coding

    It's because the formatting applied by conditional formatting isn't being recognised as 'real' formatting so VBA thinks those cells have no fill.

    So if you want to return only the data for horses in column D that don't have a match in column L then you'll need another approach.

    One way would be to add a helper column to the right of the data with this formula copied down.
    =COUNTIF($K$2:$K$256,D2)
    That will return 0 if the horse in column D isn't found in column K.

    You could then filter on the helper column.

  5. #5
    Registered User
    Join Date
    12-28-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2003
    Posts
    54

    Re: fix coding

    Hello Norie,

    Is there a way to adjust the vba coding to read the data from the formula you just gave me?

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: fix coding

    Not sure what you mean.

    You could use code to create the helper column and the filter it.
    Dim LR As Long
    Dim Rng As Range
    
        LR = Range("K" & Rows.Count).End(xlUp).Row
    
        With Cells(1, Columns.Count).End(xlToLeft).Offset(, 1)
            .Value = "Duplicate"
            Set Rng = .Resize(LR)
    
            Rng.Offset(1).Formula = "=COUNTIF($K$2:$K$" & LR & ",D2)"
    
            Rng.AutoFilter Field:=1, Criteria1:=0
    
        End With

+ 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] Vb macro coding for transpose - complete coding?
    By Dharani Suresh in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 08-02-2013, 11:16 PM
  2. [SOLVED] Vb macro coding for transpose - complete coding?
    By Dharani Suresh in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-02-2013, 05:04 AM
  3. [SOLVED] CheckBox coding to work with ComboBox coding
    By JimExcel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-05-2013, 12:23 PM
  4. Coding and Reverse Coding a Questionnaire
    By lorr3 in forum Excel General
    Replies: 2
    Last Post: 11-18-2012, 06:43 PM
  5. Implant macro coding into ASP coding
    By Sam yong in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-15-2005, 06:05 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