| | |
compare two ranges in different workbooks and copy data to a 3rd workbook
![]() |
•
•
Join Date: Feb 2008
Posts: 41
Reputation:
Solved Threads: 0
Hi
tryna get this peice of code to work but i encountered a RUN TIME ERROR 6 OVER FLOW
.
Here is how it goes:
I have two spreadsheets in different workbooks ( workbook 1: sheet 1 and workbook2: sheet1), here i need to compare column 5 in Book1 and Column 5 for all cells, say X is the value we are looking for..
X occurs once in book1 and might occur more than once in book2..so if a match occurs ( that is once the code checks that there is X occuring in both books in columns 5) it should copy all rows in book 2 where X occurs to a new workbook 3 in sheet 1 and also it shoud copy entire row data where X occurs in book 1 sheet 1
tryna get this peice of code to work but i encountered a RUN TIME ERROR 6 OVER FLOW
.Here is how it goes:
I have two spreadsheets in different workbooks ( workbook 1: sheet 1 and workbook2: sheet1), here i need to compare column 5 in Book1 and Column 5 for all cells, say X is the value we are looking for..
X occurs once in book1 and might occur more than once in book2..so if a match occurs ( that is once the code checks that there is X occuring in both books in columns 5) it should copy all rows in book 2 where X occurs to a new workbook 3 in sheet 1 and also it shoud copy entire row data where X occurs in book 1 sheet 1
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Sub wrkting() Dim b1 As Workbook Dim b2 As Workbook Dim b3 As Workbook Dim W1 As Worksheet Dim W2 As Worksheet Dim W3 As Worksheet Set b1 = Workbooks("1") Set b2 = Workbooks("1") Set b3 = Workbooks("1") Set W1 = b1.Worksheets("1") Set W2 = b2.Worksheets("1") Set W3 = b3.Worksheets("1") Dim i3 As Long Dim r As Range Dim r1 As Range Dim r2 As Range Dim c As Range Dim N As Integer Dim j1 As Integer _ Dim j3 As Integer 'j1 will be the number of columns copied from w1 to w3 'j3 will be the column to start placing the copied data from w1 in w3 'adjust as needed to fit your situation j1 = W1.Cells(2, 256).End(xlToLeft).Column j3 = W2.Cells(2, 256).End(xlToLeft).Column + 1 'next 3 lines assume headers to be skipped for column 5 processing W3.UsedRange.Offset(2, 0).Clear Set r1 = W1.Range("E3:E" & W1.Cells(65526, 5).End(xlUp).Row) Set r2 = W2.Range("E2:E" & W2.Cells(65526, 5).End(xlUp).Row) If W2.AutoFilterMode Then W2.Cells.AutoFilter i3 = 2 For Each c In r1 If Not IsEmpty(c) Then Set r = Nothing W2.Columns(5).AutoFilter 1, c.Value, xlOr, c.Value & "*" On Error Resume Next Set r = r2.SpecialCells(xlCellTypeVisible) On Error GoTo 0 If Not r Is Nothing Then i3 = i3 + 1 N = r.Cells.Count - 1 r.EntireRow.Copy W3.Cells(i3, 1) W1.Range(W1.Cells(c.Row, 1), W1.Cells(c.Row, j1)).Copy _ W3.Range(W3.Cells(i3, j3), W3.Cells(i3 + N, j3 + j1 - 1)) i3 = i3 + N End If End If Next c W2.Columns(5).AutoFilter Application.ScreenUpdating = True End Sub
![]() |
Similar Threads
- copy data from one table to other table (VB.NET)
- How to copy data from serial port to notepad (Visual Basic 4 / 5 / 6)
- Trying to copy data from one form to another form (Visual Basic 4 / 5 / 6)
- copy data from excel to vb database (Visual Basic 4 / 5 / 6)
- how to copy data into array or memory ? (C)
- copy hd data (Storage)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Problem in reading Outlook Express DBX files ...
- Next Thread: select item in combobox in html page
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





