Results 1 to 6 of 6

Move cell based on contents (VBA)

Threaded View

  1. #1
    Registered User
    Join Date
    08-25-2010
    Location
    Birmingham, England
    MS-Off Ver
    Excel 2003
    Posts
    7

    Move cell based on contents (VBA)

    Hi All,

    I'm trying to use VBA to move a cell one column to the right if it contains a comma, below is the code I'm using.

    My problem is that the code only looks to see if the whole cell value is a comma - I need it to work even if there is other text in the cell with the comma; I tried putting an asterisk either side of the comma in the code but it flagged an error...

    Any tips would be appreciated, I'm probably missing something really basic!


    Sub MoveComma()
        Dim myrange, cell As Range
        Set myrange = ActiveSheet.Range("K1", Range("K65536").End(xlUp))
        For Each cell In myrange
            If cell.Value = "," Then
                cell.Cut
                Range("K" & Application.WorksheetFunction.Max(2, cell.Row)).Offset(0, 1).Select
                ActiveSheet.Paste
            End If
        Next cell
    End Sub
    Last edited by BaronDJB; 09-02-2010 at 11:33 AM. Reason: Solved and inserted code tags

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