Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default macro to insert formula if cell format criteria satisafied

I am trying to write an Excel macro that searches a column of cells to find a
specific cell format (fill color) and enter a formula in that same row, but 2
columns over everywhere that the fill color is found.

Does any have any suggestions on how to do this?

Thanks
--
Los
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default macro to insert formula if cell format criteria satisafied


Hello Los,

Here is an example. This runs through A1:A100 on Worksheet1 looking for
Red cells. When found a formula is inserted 2 columns to the right. You
can change the worksheet name, range and formula to match your needs.


Code:
--------------------

Public Sub AddFormula()

Dim Rng As Range
Dim Formula As String

Set Rng = Worksheets("Sheet1").Range("A1:A100")
Formula = "= 2+2"

For Each Cell In Rng
If Cell.Interior.ColorIndex = vbRed Then
Cell.Offset(0, 2).Formula = Formula
End If
Next Cell

End Sub

--------------------


Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=495687

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default macro to insert formula if cell format criteria satisafied

Leith,
Thank you!
It worked with one small change. It did not recognize the color "vbRed". I
used the color index instead and it worked great.

Thanks for your help.
--
Los


"Leith Ross" wrote:


Hello Los,

Here is an example. This runs through A1:A100 on Worksheet1 looking for
Red cells. When found a formula is inserted 2 columns to the right. You
can change the worksheet name, range and formula to match your needs.


Code:
--------------------

Public Sub AddFormula()

Dim Rng As Range
Dim Formula As String

Set Rng = Worksheets("Sheet1").Range("A1:A100")
Formula = "= 2+2"

For Each Cell In Rng
If Cell.Interior.ColorIndex = vbRed Then
Cell.Offset(0, 2).Formula = Formula
End If
Next Cell

End Sub

--------------------


Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=495687


  #4   Report Post  
Posted to microsoft.public.excel.programming
AJ AJ is offline
external usenet poster
 
Posts: 99
Default macro to insert formula if cell format criteria satisafied

Is there a way to recognize the colour of the cell without using macro. For
eg, if the colour of a particluar cell (which is getting colored using
conditional formatting) is RED. Can I write (in an adjacent cell) - IF(cell
colour = RED, X,Y)

"Los in RI" wrote:

Leith,
Thank you!
It worked with one small change. It did not recognize the color "vbRed". I
used the color index instead and it worked great.

Thanks for your help.
--
Los


"Leith Ross" wrote:


Hello Los,

Here is an example. This runs through A1:A100 on Worksheet1 looking for
Red cells. When found a formula is inserted 2 columns to the right. You
can change the worksheet name, range and formula to match your needs.


Code:
--------------------

Public Sub AddFormula()

Dim Rng As Range
Dim Formula As String

Set Rng = Worksheets("Sheet1").Range("A1:A100")
Formula = "= 2+2"

For Each Cell In Rng
If Cell.Interior.ColorIndex = vbRed Then
Cell.Offset(0, 2).Formula = Formula
End If
Next Cell

End Sub

--------------------


Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=495687


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
Formula or Macro to insert Data in Cell when having more than 7 Functions pwk Excel Worksheet Functions 4 January 22nd 07 07:12 PM
Insert a new row when the criteria is met in the cell above Firefighter1 Excel Worksheet Functions 1 August 1st 06 05:38 PM
Macro to insert formula result into range with zero values in cell JPS Excel Programming 9 July 6th 05 05:56 AM
Need macro to insert text string while inside cell (formula) BrianB Excel Discussion (Misc queries) 0 May 31st 05 03:18 PM
Insert cell/format/text/fontsize and auto insert into header? Unfurltheflag Excel Programming 2 November 3rd 04 05:39 PM


All times are GMT +1. The time now is 09:31 PM.

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

About Us

"It's about Microsoft Excel"