Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
TK TK is offline
external usenet poster
 
Posts: 177
Default Match,Update & insert new data - Please HELP!

I have a master.csv (source) and myrpt.xls (destination)file, I need to match
the acct#.
1) if acct# match update the amount (total column)
2) if acct# don't match insert new data (Account, State & Total) from master
to myrpt to next blank row.

Master.csv
A B D E F
ACCOUNT State PAST_60 PAST_90 TOTAL
11-12792 CA 225.15 886.44 1,111.59
11-25851 ME 591.94 130.80 722.74
11-32239 AZ - 2,676.00 2,676.00
11-34849 AR 1,350.00 900.00 2,250.00
11-35239 ID 135.67 134.42 270.09
11-40015 CO 106.75 353.74 460.49


myrpt.xls (sheet1)
A B C
ACCOUNT State TOTAL
11-25851 ME 650.74
11-35239 ID 150.00

Thank you in advance.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Match,Update & insert new data - Please HELP!

I saved this from a similar post.

I assumed that Column E was the total line (it looked like column 5).

Open both files.

Change the names to match on these lines to match the correct sheet names:

Set MstrWks = Workbooks("master.csv").Worksheets(1)
Set UpdWks = Workbooks("myrpt.xls").Worksheets("sheet999")

Save the .csv file as a new name--just in case it's wrong. The original worked
fine, but I didn't test it with your changes.

Option Explicit
Sub testme()

Dim MstrWks As Worksheet
Dim UpdWks As Worksheet
Dim MstrKey As Range
Dim UpdKey As Range
Dim UpdCell As Range
Dim res As Variant
Dim DestRow As Long

Set MstrWks = Workbooks("master.csv").Worksheets(1)
Set UpdWks = Workbooks("myrpt.xls").Worksheets("sheet999")

With MstrWks
'remove any fill color--you'll be able to
'see the differences
.Cells.Interior.ColorIndex = xlNone
Set MstrKey = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

With UpdWks
Set UpdKey = .Range("A1", .Cells(.Rows.Count, "A").End(xlUp))
End With

For Each UpdCell In UpdKey.Cells
res = Application.Match(UpdCell.Value, MstrKey, 0)
If IsError(res) Then
'no match
With MstrWks
DestRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End With
Else
DestRow = res
End If

'now look at each field
With MstrWks
If .Cells(DestRow, "a").Value _
= UpdWks.Cells(UpdCell.Row, "a").Value Then
'no change, do nothing
Else
'changed!
With .Cells(DestRow, "a")
.Value = UpdWks.Cells(UpdCell.Row, "a").Value
.Interior.ColorIndex = 3 'red for me
End With
End If
'- - - - - - - -
If .Cells(DestRow, "b").Value _
= UpdWks.Cells(UpdCell.Row, "b").Value Then
'no change, do nothing
Else
'changed!
With .Cells(DestRow, "b")
.NumberFormat = UpdWks.Cells(UpdCell.Row, "b").NumberFormat
.Value = UpdWks.Cells(UpdCell.Row, "b").Value
.Interior.ColorIndex = 3 'red for me
End With
End If
'- - - - - - - -
'column E compared with column C, right????
'(all of the if/then/else needs to be fixed if it's wrong)
If .Cells(DestRow, "e").Value _
= UpdWks.Cells(UpdCell.Row, "c").Value Then
'no change, do nothing
Else
'changed!
With .Cells(DestRow, "E")
.Value = UpdWks.Cells(UpdCell.Row, "C").Value
.Interior.ColorIndex = 3 'red for me
End With
End If
'----------------------
End With
Next UpdCell
End Sub



TK wrote:

I have a master.csv (source) and myrpt.xls (destination)file, I need to match
the acct#.
1) if acct# match update the amount (total column)
2) if acct# don't match insert new data (Account, State & Total) from master
to myrpt to next blank row.

Master.csv
A B D E F
ACCOUNT State PAST_60 PAST_90 TOTAL
11-12792 CA 225.15 886.44 1,111.59
11-25851 ME 591.94 130.80 722.74
11-32239 AZ - 2,676.00 2,676.00
11-34849 AR 1,350.00 900.00 2,250.00
11-35239 ID 135.67 134.42 270.09
11-40015 CO 106.75 353.74 460.49

myrpt.xls (sheet1)
A B C
ACCOUNT State TOTAL
11-25851 ME 650.74
11-35239 ID 150.00

Thank you in advance.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
TK TK is offline
external usenet poster
 
Posts: 177
Default Match,Update & insert new data - Please HELP!

Thank you Dave, you rock !

"Dave Peterson" wrote:

I saved this from a similar post.

I assumed that Column E was the total line (it looked like column 5).

Open both files.

Change the names to match on these lines to match the correct sheet names:

Set MstrWks = Workbooks("master.csv").Worksheets(1)
Set UpdWks = Workbooks("myrpt.xls").Worksheets("sheet999")

Save the .csv file as a new name--just in case it's wrong. The original worked
fine, but I didn't test it with your changes.

Option Explicit
Sub testme()

Dim MstrWks As Worksheet
Dim UpdWks As Worksheet
Dim MstrKey As Range
Dim UpdKey As Range
Dim UpdCell As Range
Dim res As Variant
Dim DestRow As Long

Set MstrWks = Workbooks("master.csv").Worksheets(1)
Set UpdWks = Workbooks("myrpt.xls").Worksheets("sheet999")

With MstrWks
'remove any fill color--you'll be able to
'see the differences
.Cells.Interior.ColorIndex = xlNone
Set MstrKey = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

With UpdWks
Set UpdKey = .Range("A1", .Cells(.Rows.Count, "A").End(xlUp))
End With

For Each UpdCell In UpdKey.Cells
res = Application.Match(UpdCell.Value, MstrKey, 0)
If IsError(res) Then
'no match
With MstrWks
DestRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End With
Else
DestRow = res
End If

'now look at each field
With MstrWks
If .Cells(DestRow, "a").Value _
= UpdWks.Cells(UpdCell.Row, "a").Value Then
'no change, do nothing
Else
'changed!
With .Cells(DestRow, "a")
.Value = UpdWks.Cells(UpdCell.Row, "a").Value
.Interior.ColorIndex = 3 'red for me
End With
End If
'- - - - - - - -
If .Cells(DestRow, "b").Value _
= UpdWks.Cells(UpdCell.Row, "b").Value Then
'no change, do nothing
Else
'changed!
With .Cells(DestRow, "b")
.NumberFormat = UpdWks.Cells(UpdCell.Row, "b").NumberFormat
.Value = UpdWks.Cells(UpdCell.Row, "b").Value
.Interior.ColorIndex = 3 'red for me
End With
End If
'- - - - - - - -
'column E compared with column C, right????
'(all of the if/then/else needs to be fixed if it's wrong)
If .Cells(DestRow, "e").Value _
= UpdWks.Cells(UpdCell.Row, "c").Value Then
'no change, do nothing
Else
'changed!
With .Cells(DestRow, "E")
.Value = UpdWks.Cells(UpdCell.Row, "C").Value
.Interior.ColorIndex = 3 'red for me
End With
End If
'----------------------
End With
Next UpdCell
End Sub



TK wrote:

I have a master.csv (source) and myrpt.xls (destination)file, I need to match
the acct#.
1) if acct# match update the amount (total column)
2) if acct# don't match insert new data (Account, State & Total) from master
to myrpt to next blank row.

Master.csv
A B D E F
ACCOUNT State PAST_60 PAST_90 TOTAL
11-12792 CA 225.15 886.44 1,111.59
11-25851 ME 591.94 130.80 722.74
11-32239 AZ - 2,676.00 2,676.00
11-34849 AR 1,350.00 900.00 2,250.00
11-35239 ID 135.67 134.42 270.09
11-40015 CO 106.75 353.74 460.49

myrpt.xls (sheet1)
A B C
ACCOUNT State TOTAL
11-25851 ME 650.74
11-35239 ID 150.00

Thank you in advance.


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Match,Update & insert new data - Please HELP!

Glad it worked ok.

TK wrote:

Thank you Dave, you rock !

"Dave Peterson" wrote:

I saved this from a similar post.

I assumed that Column E was the total line (it looked like column 5).

Open both files.

Change the names to match on these lines to match the correct sheet names:

Set MstrWks = Workbooks("master.csv").Worksheets(1)
Set UpdWks = Workbooks("myrpt.xls").Worksheets("sheet999")

Save the .csv file as a new name--just in case it's wrong. The original worked
fine, but I didn't test it with your changes.

Option Explicit
Sub testme()

Dim MstrWks As Worksheet
Dim UpdWks As Worksheet
Dim MstrKey As Range
Dim UpdKey As Range
Dim UpdCell As Range
Dim res As Variant
Dim DestRow As Long

Set MstrWks = Workbooks("master.csv").Worksheets(1)
Set UpdWks = Workbooks("myrpt.xls").Worksheets("sheet999")

With MstrWks
'remove any fill color--you'll be able to
'see the differences
.Cells.Interior.ColorIndex = xlNone
Set MstrKey = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

With UpdWks
Set UpdKey = .Range("A1", .Cells(.Rows.Count, "A").End(xlUp))
End With

For Each UpdCell In UpdKey.Cells
res = Application.Match(UpdCell.Value, MstrKey, 0)
If IsError(res) Then
'no match
With MstrWks
DestRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End With
Else
DestRow = res
End If

'now look at each field
With MstrWks
If .Cells(DestRow, "a").Value _
= UpdWks.Cells(UpdCell.Row, "a").Value Then
'no change, do nothing
Else
'changed!
With .Cells(DestRow, "a")
.Value = UpdWks.Cells(UpdCell.Row, "a").Value
.Interior.ColorIndex = 3 'red for me
End With
End If
'- - - - - - - -
If .Cells(DestRow, "b").Value _
= UpdWks.Cells(UpdCell.Row, "b").Value Then
'no change, do nothing
Else
'changed!
With .Cells(DestRow, "b")
.NumberFormat = UpdWks.Cells(UpdCell.Row, "b").NumberFormat
.Value = UpdWks.Cells(UpdCell.Row, "b").Value
.Interior.ColorIndex = 3 'red for me
End With
End If
'- - - - - - - -
'column E compared with column C, right????
'(all of the if/then/else needs to be fixed if it's wrong)
If .Cells(DestRow, "e").Value _
= UpdWks.Cells(UpdCell.Row, "c").Value Then
'no change, do nothing
Else
'changed!
With .Cells(DestRow, "E")
.Value = UpdWks.Cells(UpdCell.Row, "C").Value
.Interior.ColorIndex = 3 'red for me
End With
End If
'----------------------
End With
Next UpdCell
End Sub



TK wrote:

I have a master.csv (source) and myrpt.xls (destination)file, I need to match
the acct#.
1) if acct# match update the amount (total column)
2) if acct# don't match insert new data (Account, State & Total) from master
to myrpt to next blank row.

Master.csv
A B D E F
ACCOUNT State PAST_60 PAST_90 TOTAL
11-12792 CA 225.15 886.44 1,111.59
11-25851 ME 591.94 130.80 722.74
11-32239 AZ - 2,676.00 2,676.00
11-34849 AR 1,350.00 900.00 2,250.00
11-35239 ID 135.67 134.42 270.09
11-40015 CO 106.75 353.74 460.49

myrpt.xls (sheet1)
A B C
ACCOUNT State TOTAL
11-25851 ME 650.74
11-35239 ID 150.00

Thank you in advance.


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
TK TK is offline
external usenet poster
 
Posts: 177
Default Match,Update & insert new data - Please HELP!

Thanks a million Dave - I just had to few changes & it worked perfectly. You
are the best !

"TK" wrote:

I have a master.csv (source) and myrpt.xls (destination)file, I need to match
the acct#.
1) if acct# match update the amount (total column)
2) if acct# don't match insert new data (Account, State & Total) from master
to myrpt to next blank row.

Master.csv
A B D E F
ACCOUNT State PAST_60 PAST_90 TOTAL
11-12792 CA 225.15 886.44 1,111.59
11-25851 ME 591.94 130.80 722.74
11-32239 AZ - 2,676.00 2,676.00
11-34849 AR 1,350.00 900.00 2,250.00
11-35239 ID 135.67 134.42 270.09
11-40015 CO 106.75 353.74 460.49


myrpt.xls (sheet1)
A B C
ACCOUNT State TOTAL
11-25851 ME 650.74
11-35239 ID 150.00

Thank you in advance.



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
INDEX/MATCH update limitation mariekek5 New Users to Excel 3 June 5th 09 11:25 PM
How to insert a row and not update existing formulas? Bobshaw Excel Discussion (Misc queries) 2 November 17th 08 09:36 AM
Data Validation lists update orginal cell with list update [email protected] Excel Worksheet Functions 3 July 11th 08 07:56 AM
Update of cell values after insert row? dazman Excel Worksheet Functions 2 August 23rd 05 07:07 AM
insert into a cell the last update Ramiro Cubillan Excel Worksheet Functions 1 December 29th 04 08:45 PM


All times are GMT +1. The time now is 06:08 AM.

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"