+ Reply to Thread
Results 1 to 2 of 2

VBA Code for Selective formula writing

  1. #1
    Registered User
    Join Date
    08-24-2005
    Posts
    1

    VBA Code for Selective formula writing

    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.

  2. #2
    Bernie Deitrick
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    >
    > 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
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1