Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
conditionally adding a cell
Hello! I'm new to excel macros and trying to set up a macro that runs throug a file row by row and inserts a cell before columnF (shifting cells t the left) if the value in column C="forced". It seems like it shoul be quite simple, but I can't figure it out. Any help would b fantastic. thanks! -justin -- newbie09 ----------------------------------------------------------------------- newbie099's Profile: http://www.excelforum.com/member.php...fo&userid=3385 View this thread: http://www.excelforum.com/showthread.php?threadid=53636 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
conditionally adding a cell
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 not 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 Su -- mudrake ----------------------------------------------------------------------- mudraker's Profile: http://www.excelforum.com/member.php...nfo&userid=247 View this thread: http://www.excelforum.com/showthread.php?threadid=53636 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
conditionally adding a cell
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 -- newbie09 ----------------------------------------------------------------------- newbie099's Profile: http://www.excelforum.com/member.php...fo&userid=3385 View this thread: http://www.excelforum.com/showthread.php?threadid=53636 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Conditionally formatting a cell based on other cell values | Excel Worksheet Functions | |||
Conditionally protect a cell | Excel Discussion (Misc queries) | |||
How to conditionally reference a cell | Excel Worksheet Functions | |||
Conditionally Formatting a Cell | Excel Programming | |||
Conditionally clearing a cell | Excel Programming |