Compare Two column and put the value in 3rd column
Attend Excelapalooza
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 6 of 6

Thread: Compare Two column and put the value in 3rd column

  1. #1
    Board Regular
    Join Date
    Apr 2017
    Posts
    58
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Compare Two column and put the value in 3rd column

     
    Hi,
    I want the desired result in Z column though VBA
    X Y Z
    Plan Actual Desired Result
    10 10 10
    0 20 0
    20 30 20
    30 40 30
    0 50 0
    40 40
    0 0
    50 50
    60 0
    0 0
    0 0
    0 0
    70 0
    80 0
    90 0
    0 0

    My code is not working. Kindly help.
    Code:
    Sub test()Dim X As Range, Y As Range, Z As Range
    
    
    For Each X In Range("A5:A20")
        For Each Y In Range("B5:B20")
            For Each Z In Range("C5:C20")
                If X = 0 Then
                Z = 0
                'End If
                        Else
                    If X <> 0 Then
                    Z = X.Value
                End If
                End If
            Next Z
        Next Y
    Next X
    
    
    End Sub

  2. #2
    Board Regular igold's Avatar
    Join Date
    Jul 2014
    Location
    Delray Beach, FL, USA
    Posts
    1,881
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Compare Two column and put the value in 3rd column

    Perhaps you could explain what is supposed to happen. From looking at your data, I do not see any kind of consistent relationship between the column values...
    ​igold

    I'm a drinker with a coding problem...

    All code is written with Excel 2010 - Please test all code on a backup copy of your data.


  3. #3
    Board Regular
    Join Date
    Apr 2017
    Posts
    58
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Compare Two column and put the value in 3rd column

    igold, thank you for your time.
    I'm sorry for not making the request clearly.

    What I have is X column the plan data and Y column as actual data.
    I need to display in Z column against X and Y row, if plan is 0 then Z column need to be filled with 0, else to fetch actual data in Z column in order.

  4. #4
    Board Regular igold's Avatar
    Join Date
    Jul 2014
    Location
    Delray Beach, FL, USA
    Posts
    1,881
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Compare Two column and put the value in 3rd column

    if X is not zero and Y is empty, what does Z equal...
    ​igold

    I'm a drinker with a coding problem...

    All code is written with Excel 2010 - Please test all code on a backup copy of your data.


  5. #5
    Board Regular
    Join Date
    Apr 2017
    Posts
    58
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Compare Two column and put the value in 3rd column

    Exit Sub.

  6. #6
    Board Regular
    Join Date
    Apr 2017
    Posts
    58
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Compare Two column and put the value in 3rd column

      
    Hi,
    I found a work around with below code.Forking fine.
    Any suggestion to do do it better.
    Code:
    Sub test()
    Dim x As Range
    Dim i As String
    
    For Each x In Range(""A1:A15")
    i = x.Address
      If x = 0 Then
       Range(i).Offset(, 1).Insert Shift:=xlDown
      End If
      Next x
      MsgBox "Done"
    End Sub

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com