+ Reply to Thread
Results 1 to 3 of 3

Deleting content in cells based on criteria

Hybrid View

  1. #1
    Registered User
    Join Date
    09-27-2007
    Posts
    17

    Deleting content in cells based on criteria

    Hi,

    If I have a range..say A2:A200, how would I write a macro that does the following

    If the value of the cell in the defined range does not equal 0, 1 or 2
    Delete the contents of the cell

    If the cell = 0 in the defined range, allign left
    If the cell = 1 in the defined range, allign center
    If the cell = 2 in the defined range, allign right


    I'm sure it's much easier then I think it is...any help would be greatly appreciated.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    Try this:
    Sub x()
    
    Dim rng As Range
    
    For Each rng In Range("A2:A200")
        Select Case rng
            Case 0: rng.HorizontalAlignment = xlLeft
            Case 1: rng.HorizontalAlignment = xlCenter
            Case 2: rng.HorizontalAlignment = xlRight
            Case Else: rng.Clear
        End Select
    Next rng
    
    End Sub

  3. #3
    Registered User
    Join Date
    09-27-2007
    Posts
    17
    perfect! thank you

+ 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