+ Reply to Thread
Results 1 to 7 of 7

Restrict the macro in a particular column

Hybrid View

  1. #1
    Registered User
    Join Date
    06-17-2012
    Location
    UNITED STATES
    MS-Off Ver
    Excel 2010
    Posts
    29

    Restrict the macro in a particular column

    Hi,

    I have data in column 'H' where I want to add string "No cases" after number (whereever there, no need to touch that row). Condition is that after record number 6, I want to delete the cell (not complete row )where equal to zero (i.e.mark=0) is present.

    Problem is that, when I run the macro, data from column A-F are also affected. How to restrict it in column H only and delete cells with equal to (=0) from 7th records onwards
    Data are like this----->
    Boys mark Physics=50
    Boys mark non-Physics=1
    Boys games in Physics=11
    Boys games in non-Physics=No Cases
    Girls mark Physics=2
    Girls mark non-Physics=27
    Girls/non-games/Physics/Boys/in=1088
    mark=0
    ames in non-Physics=0

    
    Sub PROB()
    LR = Range("H" & Rows.Count).End(xlUp).Row
    Set Rng = Range(Cells(1, 1), Cells(LR, 1))
    For i = Rng.Count To 1 Step -1
    
    Pos = InStrRev(Cells(i, 1), "=")
    If IsNumeric(Right(Cells(i, 1), Len(Cells(i, 1)) - Pos)) And Right(Cells(i, 1), Len(Cells(i, 1)) - Pos) <> 0 Then
    If Right(Cells(i, 1), Len(Cells(i, 1)) - Pos) > 1 Then
    Cells(i, 1).Value = Cells(i, 1).Value & " Cases"
    ElseIf Right(Cells(i, 1), Len(Cells(i, 1)) - Pos) = 1 Then
    Cells(i, 1).Value = Cells(i, 1).Value & " Case"
    End If
    Else
    Cells(i, 1).EntireRow.Delete
    End If
    
    Next i
    End Sub
    Last edited by cruise.alter; 06-24-2012 at 01:05 PM. Reason: rule violation

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,042

    Re: Need help on VBA

    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.

    Never use Merged Cells in Excel

  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,042

    Re: Need help on VBA

    Your post does not comply with Rule 3 of our Forum RULES. 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 # at the top of your post window. For more information about these and other tags, found here

  4. #4
    Registered User
    Join Date
    06-17-2012
    Location
    UNITED STATES
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Restrict the macro in a particular column

    Apolgoies.......I have updated

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Restrict the macro in a particular column

    Hi cruise.alter,

    Don't you want:

    Cells(i, 1).ClearContents
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  6. #6
    Registered User
    Join Date
    06-17-2012
    Location
    UNITED STATES
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Restrict the macro in a particular column

    I want the macro to run at column H only without affecting other column along with the criteria which I mentioned above.
    Can it be possible

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Restrict the macro in a particular column

    Hi cruise.alter,

    How about:

    Cells(i, 8).ClearContents

+ 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