+ Reply to Thread
Results 1 to 4 of 4

conditionally adding a cell

  1. #1
    Registered User
    Join Date
    04-26-2006
    Posts
    4

    conditionally adding a cell

    Hello!

    I'm new to excel macros and trying to set up a macro that runs through a file row by row and inserts a cell before columnF (shifting cells to the left) if the value in column C="forced". It seems like it should be quite simple, but I can't figure it out. Any help would be fantastic. thanks!

    -justine

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    justine

    you can not insert cells and push items to the left or up.

    this code will insert a cell into column f (moving cells to the right) if the cell in column c (same row) has a value of forced - please note that the if statement is case sensative
    eg forced does not test the same as Forced

    Sum InsertCell
    Dim Rng As Range
    For Each Rng In Column("c")
    If Rng.Value = "forced" Then
    Cells(Rng.Row, "f").Insert Shift:=xlToRight
    End If
    Next Rng
    End Sub

  3. #3
    Tom Ogilvy
    Guest

    RE: conditionally adding a cell

    to the best of my knowledge, there is no support in VBA or manually for
    shifting cells to the left unless you are deleting. But you say you are
    inserting.

    Sub InsertCells()
    lastrow = cells(rows.count,3).End(xlup).row
    for i = lastrow to 1 step -1
    if cells(i,3) = "forced" then
    cells(i,"F").Insert Shift:=xlShiftToRight
    end if
    Next
    end Sub

    --
    Regards,
    Tom Ogilvy


    "newbie099" wrote:

    >
    > Hello!
    >
    > I'm new to excel macros and trying to set up a macro that runs through
    > a file row by row and inserts a cell before columnF (shifting cells to
    > the left) if the value in column C="forced". It seems like it should
    > be quite simple, but I can't figure it out. Any help would be
    > fantastic. thanks!
    >
    > -justine
    >
    >
    > --
    > newbie099
    > ------------------------------------------------------------------------
    > newbie099's Profile: http://www.excelforum.com/member.php...o&userid=33857
    > View this thread: http://www.excelforum.com/showthread...hreadid=536362
    >
    >


  4. #4
    Registered User
    Join Date
    04-26-2006
    Posts
    4
    So sorry! I meant to the right!

    I tried this, but got an error when it got to "column("C")


    Sum InsertCell
    Dim Rng As Range
    For Each Rng In Column("c")
    If Rng.Value = "forced" Then
    Cells(Rng.Row, "f").Insert Shift:=xlToRight
    End If
    Next Rng
    End Sub


    It says "Compile error: Sub or Function not defined"

+ 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