+ Reply to Thread
Results 1 to 4 of 4

Populating fields based on previous column values

  1. #1
    MMH
    Guest

    Populating fields based on previous column values

    Hello

    I am trying to populate the cells in a column (column F) based on
    information in columns B, C and D. Unfortunately I do not know how to code
    this.

    For example, I want to say that for all the rows where column C equals "AC",
    column F should say "Agent's Charges". Then for all the rows where column D
    has "OF", column F should say "Official Fees". And so on.

    Could someone please tell me how I would write this in VBA. Thank you in
    advance.

    MMH

  2. #2
    Edwin Tam
    Guest

    RE: Populating fields based on previous column values

    You may use the IF-THEN-ELSE conditional statements. Below is a simple example.

    To test using the macro, populate some cells in column C and D with the
    words you specified. Then select the adjacent cells in column F. Then run the
    macro.

    Sub checking()
    Dim cell As Object
    For Each cell In Selection.Cells
    If cell.Offset(0, -3).Value = "AC" Then
    cell.Value = "Agent's Charges"
    ElseIf cell.Offset(0, -2).Value = "OF" Then
    cell.Value = "Official Fees"
    ElseIf cell.Offset(0, -4).Value = "XXXX" Then
    'do something else
    End If
    Next
    End Sub


    Basically, for example, for a cell F1, the "cell.offset(0,-2).value" is
    referring to the value of the cell in D1, i.e. 2 cells to the left.

    Feel free to ask if you need further assistance. :>

    Regards,
    Edwin Tam
    [email protected]
    http://www.vonixx.com



    "MMH" wrote:

    > Hello
    >
    > I am trying to populate the cells in a column (column F) based on
    > information in columns B, C and D. Unfortunately I do not know how to code
    > this.
    >
    > For example, I want to say that for all the rows where column C equals "AC",
    > column F should say "Agent's Charges". Then for all the rows where column D
    > has "OF", column F should say "Official Fees". And so on.
    >
    > Could someone please tell me how I would write this in VBA. Thank you in
    > advance.
    >
    > MMH


  3. #3
    Patrick Molloy
    Guest

    RE: Populating fields based on previous column values

    why don't you just use a VLOOKUP function?

    "MMH" wrote:

    > Hello
    >
    > I am trying to populate the cells in a column (column F) based on
    > information in columns B, C and D. Unfortunately I do not know how to code
    > this.
    >
    > For example, I want to say that for all the rows where column C equals "AC",
    > column F should say "Agent's Charges". Then for all the rows where column D
    > has "OF", column F should say "Official Fees". And so on.
    >
    > Could someone please tell me how I would write this in VBA. Thank you in
    > advance.
    >
    > MMH


  4. #4
    MMH
    Guest

    RE: Populating fields based on previous column values

    Thanks Edwin - that does exactly what I wanted it to.

    MMH

    "Edwin Tam" wrote:

    > You may use the IF-THEN-ELSE conditional statements. Below is a simple example.
    >
    > To test using the macro, populate some cells in column C and D with the
    > words you specified. Then select the adjacent cells in column F. Then run the
    > macro.
    >
    > Sub checking()
    > Dim cell As Object
    > For Each cell In Selection.Cells
    > If cell.Offset(0, -3).Value = "AC" Then
    > cell.Value = "Agent's Charges"
    > ElseIf cell.Offset(0, -2).Value = "OF" Then
    > cell.Value = "Official Fees"
    > ElseIf cell.Offset(0, -4).Value = "XXXX" Then
    > 'do something else
    > End If
    > Next
    > End Sub
    >
    >
    > Basically, for example, for a cell F1, the "cell.offset(0,-2).value" is
    > referring to the value of the cell in D1, i.e. 2 cells to the left.
    >
    > Feel free to ask if you need further assistance. :>
    >
    > Regards,
    > Edwin Tam
    > [email protected]
    > http://www.vonixx.com


+ 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