Consulting

Results 1 to 3 of 3

Thread: Remove blank cells to left if condition

  1. #1

    Remove blank cells to left if condition

    Hi all,
    Please I need some help.
    I have four columns, A & B are blank, C has numbers and words, D has a description if the column before it has a word.
    What I am trying to do is if column C contains a word or string then move it and its description to column A & B.
    I have tried if cell contains a word change its offset (0,-2) or remove the blanks by using special cells.
    Nothing I am doing gets the desired result, any help or pointers would be appreciated.

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    try:
    Sub blah()
    For Each are In Columns(3).SpecialCells(xlCellTypeConstants, 2).Areas
      are.Resize(, 2).Cut are.Offset(, -2)
    Next are
    End Sub
    If this fails then post a sample file.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Try this, sample WB attached


    Option Explicit
    
    Sub Macro1()
        Dim rData As Range, rArea As Range
    
        On Error Resume Next
        Set rData = Columns("C:D").SpecialCells(xlCellTypeConstants, 2)
        On Error GoTo 0
        If rData Is Nothing Then Exit Sub
    
        Application.ScreenUpdating = False
        For Each rArea In rData.Areas
            Call rArea.Copy(Cells(rArea.Row, 1))
        Next
        
        Application.CutCopyMode = False
        
        Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •