Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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 wit
duplicate employee id columns (col G and Z) and phone number column
(col H and AA). Only the AA phone number column has data and I need t
move it to the other column based on matching columns G and Z. I wrot
this little bit of code, but it's not working? Can someone pleas
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


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

--
panuvi
-----------------------------------------------------------------------
panuvin's Profile:
http://www.excelforum.com/member.php...fo&userid=2381
View this thread: http://www.excelforum.com/showthread.php?threadid=37466

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default 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" wrote in
message ...

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


** 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
2 columns need one figure substracted from another cell poncho Excel Discussion (Misc queries) 2 February 12th 09 09:35 PM
Formatting columns with either a date OR a numerical figure Terry Winter Excel Worksheet Functions 1 October 29th 06 11:45 AM
merge text from 2 columns into 1 then delete the old 2 columns sleepindogg Excel Worksheet Functions 4 March 30th 06 07:25 PM
how to find negative figure in various columns and rows HOW TO GO TO SHEET1 FROM WHILE WORKING I Excel Discussion (Misc queries) 2 January 25th 06 08:52 AM
1-7 Columns, to find last column with figure in sonar Excel Worksheet Functions 3 September 1st 05 06:04 AM


All times are GMT +1. The time now is 10:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"