+ Reply to Thread
Results 1 to 2 of 2

Cell data depending on column selected.

  1. #1

    Cell data depending on column selected.

    A pretty simple VBA problem in excel

    I am trying to create a simple module to input either P1 or P2 in
    selected cells.

    If the column selected is D, E, F G

    D and E should equal P1
    F and G should equal P2

    This should work for any combination such as if only D or G is selected
    D = P1, G = P2.

    I have the following worked out but I cannot get it to fill in the
    cells properly, if I only select a single cell it works fine, but if I
    select D - G it fills it all with P1.

    code:
    Sub CellFill()

    If (ActiveCell.Column = 4 Or ActiveCell.Column = 5) Then
    ActiveCell.Value = "P1"
    Else
    ActiveCell.Value = "P2"
    End If

    End Sub
    /code



    Any help is appreciated


  2. #2
    Bob Phillips
    Guest

    Re: Cell data depending on column selected.

    Sub CellFill()
    Dim cell As Range

    For Each cell In Selection
    If (cell.Column = 4 Or cell.Column = 5) Then
    cell.Value = "P1"
    Else
    cell.Value = "P2"
    End If
    Next cell

    End Sub



    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    <[email protected]> wrote in message
    news:[email protected]...
    > A pretty simple VBA problem in excel
    >
    > I am trying to create a simple module to input either P1 or P2 in
    > selected cells.
    >
    > If the column selected is D, E, F G
    >
    > D and E should equal P1
    > F and G should equal P2
    >
    > This should work for any combination such as if only D or G is selected
    > D = P1, G = P2.
    >
    > I have the following worked out but I cannot get it to fill in the
    > cells properly, if I only select a single cell it works fine, but if I
    > select D - G it fills it all with P1.
    >
    > code:
    > Sub CellFill()
    >
    > If (ActiveCell.Column = 4 Or ActiveCell.Column = 5) Then
    > ActiveCell.Value = "P1"
    > Else
    > ActiveCell.Value = "P2"
    > End If
    >
    > End Sub
    > /code
    >
    >
    >
    > Any help is appreciated
    >




+ 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