+ Reply to Thread
Results 1 to 2 of 2

Can't figure out how to merge columns

  1. #1
    Registered User
    Join Date
    05-27-2005
    Posts
    2

    Question Can't figure out how to merge columns

    Hello, I'm rather new to Excel and VBA programming, but being a C++ programmer has helped me a little bit. I've got two spreadsheets with duplicate employee id columns (col G and Z) and phone number columns (col H and AA). Only the AA phone number column has data and I need to move it to the other column based on matching columns G and Z. I wrote this little bit of code, but it's not working? Can someone please point me in the right direction. Thanks!

    Sub Fixit()
    Dim i As Integer
    Dim j As Integer

    For i = 2 To 3261
    For j = 10 To 6510
    If Cells(i, Z).Value = Cells(j, G).Value Then _
    Cells(i, H).Value = Cells(j, AA).Value
    Next j
    Next i
    End Sub

    Justin Robinson
    [email protected]

    ** You'll notice the Z/AA columns are smaller in size.

  2. #2
    Mike Fogleman
    Guest

    Re: Can't figure out how to merge columns

    Sub Fixit()
    Dim i As Long
    Dim j As Long

    For i = 2 To 3261
    For j = 10 To 6510
    If Cells(i, 26).Value = Cells(j, 7).Value Then _
    Cells(i, 8).Value = Cells(j, 27).Value
    Next j
    Next i
    End Sub

    Note: This will only work if the Employee IDs in columns G & Z match each
    other with sort order and length of data.
    Second, you are comparing 2 different size ranges. Your i range is
    "Z2:Z3261", and your j range is "G10:G6510", almost twice the size. Your
    code is going to run out of i before j is finished.
    Is there any reason a VLookup would not work for you?

    Mike F

    "panuvin" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hello, I'm rather new to Excel and VBA programming, but being a C++
    > programmer has helped me a little bit. I've got two spreadsheets with
    > duplicate employee id columns (col G and Z) and phone number columns
    > (col H and AA). Only the AA phone number column has data and I need to
    > move it to the other column based on matching columns G and Z. I wrote
    > this little bit of code, but it's not working? Can someone please
    > point me in the right direction. Thanks!
    >
    > Sub Fixit()
    > Dim i As Integer
    > Dim j As Integer
    >
    > For i = 2 To 3261
    > For j = 10 To 6510
    > If Cells(i, Z).Value = Cells(j, G).Value Then _
    > Cells(i, H).Value = Cells(j, AA).Value
    > Next j
    > Next i
    > End Sub
    >
    > Justin Robinson
    > [email protected]
    >
    > ** You'll notice the Z/AA columns are smaller in size.
    >
    >
    > --
    > panuvin
    > ------------------------------------------------------------------------
    > panuvin's Profile:
    > http://www.excelforum.com/member.php...o&userid=23818
    > View this thread: http://www.excelforum.com/showthread...hreadid=374662
    >




+ 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