Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditionally formatting a cell based on other cell values ian Excel Worksheet Functions 3 February 27th 10 10:27 PM
Conditionally protect a cell bigjim Excel Discussion (Misc queries) 2 February 27th 09 08:18 PM
How to conditionally reference a cell Mike_n_TX Excel Worksheet Functions 3 May 13th 07 03:43 AM
Conditionally Formatting a Cell Floyd[_2_] Excel Programming 14 September 30th 05 02:02 AM
Conditionally clearing a cell Don Rountree[_2_] Excel Programming 1 November 28th 03 06:09 PM


All times are GMT +1. The time now is 08:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"