+ Reply to Thread
Results 1 to 6 of 6

Make this code column specific?

Hybrid View

  1. #1
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Question Make this code column specific?

    Hi folks,

    here is my code which looks up a piece of data from one sheet in another and clears it if it is present. (special thanks to RoyUK for the code)

    Sub Rectangle18_Click()
    
        Dim i, j As Long
        
        For i = 4 To Sheets("Teams Used").Range("A" & Rows.Count).End(xlUp).Row
            For j = Sheets("Teams Left").Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
                If Sheets("Teams Used").Range("A" & i).Value = Sheets("Teams Left").Range("A" & j).Value Then
                   Sheets("Teams left").Rows(j).ClearContents
                End If
            Next j
        Next i
    
    End Sub
    However i have lots of different colums in the sheet anmd i need it to only delete from a set colum in this case column "A" only.

    please help folks

    thanks for reading my thread and cheers for any help

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Dave that's not my code and it looks specific to Column A. Is this what you want
    Sub Rectangle18_Click()
    
        Dim i, j As Long
        
        For i = 4 To Sheets("Teams Used").Range("A" & Rows.Count).End(xlUp).Row
            For j = Sheets("Teams Left").Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
                If Sheets("Teams Used").Range("A" & i).Value = Sheets("Teams Left").Range("A" & j).Value Then
    'clear only cell in A
                   Sheets("Teams left").Cells("A" & j).ClearContents
                End If
            Next j
        Next i
    
    End Sub
    Hope that helps.

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

    Free DataBaseForm example

  3. #3
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Thumbs up God Damn Roy

    Roy Roy Roy Roy,

    what would i do without you? probabbly be jobless mate.

    Top work as ever Buddy

  4. #4
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Debug Issue

    Hi Roy

    'clear only cell in A
                   Sheets("Teams left").Cells("A" & j).ClearContents
    for some reason the code does not work and this line is highlighted when i try and Debug the code.

    PLease help (Hands in the prayer position)

  5. #5
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    Try to change so your code:
    Sheets("Teams left").Range("A" & j).ClearContents
    or
    Sheets("Teams left").Cells(j, "A").ClearContents
    Regards,
    Antonio

  6. #6
    Valued Forum Contributor Macdave_19's Avatar
    Join Date
    03-14-2007
    Location
    Birmingham, England
    MS-Off Ver
    12.0
    Posts
    808

    Thumbs up Woo Hoo

    Antonio Your a top man,

    i been messing with that code for ages too

    Thanks very much!!

+ 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