Thread: Table Update
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Table Update

This worked ok for me. But it overwrites the original sheet1. So save your
work before you start.

Close the workbook without saving if it's not right:

Option Explicit
Sub testme()
Dim wks1 As Worksheet
Dim wks2 As Worksheet
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim res As Variant

Set wks1 = Worksheets("sheet1")
Set wks2 = Worksheets("sheet2")

With wks2
FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = LastRow To FirstRow Step -1
res = Application.Match(.Cells(iRow, "A").Value, _
wks1.Range("a:a"), 0)
If IsError(res) Then
MsgBox "error with row#: " & iRow
Exit Sub
End If

wks1.Cells(res, 2).Insert Shift:=xlToRight
wks1.Cells(res, 2).Value = .Cells(iRow, "B").Value
Next iRow
End With

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

phil2006 wrote:

If I have the following table (sheet1):
A 1 2 3 4 5
B 4 5 6 7 8
C 1 9 0 3 7

..and then (sheet2)

A 1
B 1
A 2
C 6
B 2
A 3
..is there a macro or programme I could run which would insert the
values from sheet 2 in order into the rows on sheet one to give:
A 1 2 3 1 2 3 4 5
B 1 2 4 5 6 7 8
C 6 1 9 0 3 7

Thanks very much!

--
phil2006
------------------------------------------------------------------------
phil2006's Profile: http://www.excelforum.com/member.php...o&userid=35092
View this thread: http://www.excelforum.com/showthread...hreadid=549543


--

Dave Peterson