ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA Code for Selective formula writing (https://www.excelbanter.com/excel-programming/338164-vba-code-selective-formula-writing.html)

Fuerteventura

VBA Code for Selective formula writing
 

I need to write some VBA code which will write formula into several row
- however, I want it to select which rows it writes the code int
depending upon the following

Sheet1

(Row Number) ID Price
1 1234 (Formula which will be written if applicable)
2 4321 (Formula which will be written if applicable)
3 5678 (Formula which will be written if applicable)


Sheet2
ID
1234

In this case, I would only want to write the formula into line 1 i
sheet1.

is this possible? maybe an If statement or something or a For Each Row
= 1 to X????
Cheers

--
Fuerteventur
-----------------------------------------------------------------------
Fuerteventura's Profile: http://www.excelforum.com/member.php...fo&userid=2658
View this thread: http://www.excelforum.com/showthread.php?threadid=39856


Bernie Deitrick

VBA Code for Selective formula writing
 
Fuerteventura,

Dim myCell As Range
For Each myCell In Worksheets("Sheet1").Range("A2:A4")
If Not (IsError(Application.Match(myCell.Value, _
Worksheets("Sheet2").Range("A:A"), False))) Then
myCell(1, 2).Formula = "=Formula which will be written....."
End If
Next myCell

Or you could just use an if formula in all the cells, that returns "" when the value isn't found....

HTH,
Bernie
MS Excel MVP


"Fuerteventura" wrote in message
news:Fuerteventura.1u9s2i_1124888738.4429@excelfor um-nospam.com...

I need to write some VBA code which will write formula into several rows
- however, I want it to select which rows it writes the code into
depending upon the following

Sheet1

(Row Number) ID Price
1 1234 (Formula which will be written if applicable)
2 4321 (Formula which will be written if applicable)
3 5678 (Formula which will be written if applicable)


Sheet2
ID
1234

In this case, I would only want to write the formula into line 1 in
sheet1.

is this possible? maybe an If statement or something or a For Each Rows
= 1 to X????
Cheers.


--
Fuerteventura
------------------------------------------------------------------------
Fuerteventura's Profile: http://www.excelforum.com/member.php...o&userid=26586
View this thread: http://www.excelforum.com/showthread...hreadid=398560





All times are GMT +1. The time now is 12:02 AM.

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