ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   conditionally adding a cell (https://www.excelbanter.com/excel-programming/359820-conditionally-adding-cell.html)

newbie099

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


mudraker[_372_]

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


Tom Ogilvy

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



newbie099[_2_]

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



All times are GMT +1. The time now is 09:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com