Results 1 to 2 of 2

Thread: Filling Excel Columns with a Condition

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    3

    Filling Excel Columns with a Condition

    I am working in Excel and I have 2 columns.

    for example

    A B C
    140000

    5453 (140000)
    6764 (140000)
    3373 (140000)

    140001
    3623 (140001)
    2547 (140001)


    I want Excel to go through the spreadsheet and filling column A into Column C, next to the value in B. However Column A has other values in it but if I could use a condition > than 140000 to pull the numbers I want.


    Parenthesis is the output I want.
    Hope this is clear,

    Thanks

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    I think I've understood that one there. This script will look at each cell value in turn in column A. If the value in this cell is less than 14000, the value copied into the corresponding column C cell will equal 14000, otherwise, if the value in cell A is greater than 14000, this value itself is copied across to the corresponding column C cell.
    VB Code:
    1. Private Sub CommandButton1_Click()
    2.     Dim lngCounter As Long
    3.    
    4.     For lngCounter = 1 To ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
    5.         If (Cells(lngCounter, 1).Value < 140000) Then
    6.             Cells(lngCounter, 3).Value = 140000
    7.         Else
    8.             Cells(lngCounter, 3).Value = Cells(lngCounter, 3).Value
    9.         End If
    10.     Next lngCounter
    11. End Sub

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

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



Click Here to Expand Forum to Full Width