Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Comparing info between worksheets

I could really use some help with a macro. It has been several years
since I did any macro programming and I feel completely lost.

I have recently volunteered my services to the local waterboard to
help them with their books. They are really a mess. One Excel file
has a worksheet with all the original water accounts then a second
worksheet that has all the current billing information, this account
is always updated. The problem is that no one ever updated the Main
Accounts worksheet or otherwise known as the Original accounts
worksheet.


So here is the problem:

Worksheet that is named "Main accounts"
Columns A: Person's name, Column C: Account number Column E:
Address

Worksheet that is named "Current accounts"
Column A: Person's name, Column D: Account numbers Column G:
Address

What I was trying to do unsuccessfully was create a macro that would
go through the worksheet named "Main accounts" check the account
numbers in Column C (Account number column) and look at the name that
is in Column A for that account number.

It would then compare the name that is assigned to the account number
with the name in the worksheet "Current accounts" and if the name was
different it would then put the current name for that account number
on the Main accounts worksheet.

One extra part if possible would be to add the correct address from
the worksheet named "Current accounts" to the address column on the
"Main accounts" worksheet in column E.

One of my fears is that someone might have added accounts to the
Current worksheet and not include it on the Main worksheet. I would
really appreciate some help with this.

Also if you could recommend a website or book that would help me brush
up on my programming skills I would truly appreciate it.

Thank you
LeeLee

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Comparing info between worksheets

I don't think you need a macro to do this. I think you could use some helper
columns and some additional formulas.

For instance....

I'd do this:
In the Main Accounts worksheet

insert two new columns to the right of the name (new column B and C).

Put this in B1: Name From Current
Put this in C1: Name to Use
(they're just headers)

In B2:
=INDEX('Current Accounts'!A:A,MATCH(E2,'Current Accounts'!D:D,0))
(all one line)

This will return the name that matches that account number that's in E2 (shifted
to columns to the right, remember?). Or it will return an error if there is no
match.

Then in C2:
=if(iserror(b2),a2,b2)

If an error was returned, then use the old name (in A2). Otherwise, use the
current name that's in B2--even if it matches (or not!) what's in A2.

Then copy those formulas down as many rows as you need.

======
And the same thing for the addresses.
Insert a new column H and I (since things are shifting to the right!)
In H1: Address From Current
In I1: Address to Use

In H2:
=INDEX('Current Accounts'!g:g,MATCH(E2,'Current Accounts'!D:D,0))
In I2:
=if(iserror(h2),g2,h2)

And copy those down as far as you want.

Then I'd convert those formulas to values
Select B:C
edit|Copy
edit|Paste special|Values

And same with H:I

=========
Another thing you may want to check (if you're curious) is if the names (and/or
addresses) changed.

Just put another formula that compares A2:C2 (assuming that column B wasn't
deleted)
=A2=C2
(this'll return true if they match, False if they don't.)

============
If I were doing this as a macro, I'd essentially do the same steps.


wrote:

I could really use some help with a macro. It has been several years
since I did any macro programming and I feel completely lost.

I have recently volunteered my services to the local waterboard to
help them with their books. They are really a mess. One Excel file
has a worksheet with all the original water accounts then a second
worksheet that has all the current billing information, this account
is always updated. The problem is that no one ever updated the Main
Accounts worksheet or otherwise known as the Original accounts
worksheet.

So here is the problem:

Worksheet that is named "Main accounts"
Columns A: Person's name, Column C: Account number Column E:
Address

Worksheet that is named "Current accounts"
Column A: Person's name, Column D: Account numbers Column G:
Address

What I was trying to do unsuccessfully was create a macro that would
go through the worksheet named "Main accounts" check the account
numbers in Column C (Account number column) and look at the name that
is in Column A for that account number.

It would then compare the name that is assigned to the account number
with the name in the worksheet "Current accounts" and if the name was
different it would then put the current name for that account number
on the Main accounts worksheet.

One extra part if possible would be to add the correct address from
the worksheet named "Current accounts" to the address column on the
"Main accounts" worksheet in column E.

One of my fears is that someone might have added accounts to the
Current worksheet and not include it on the Main worksheet. I would
really appreciate some help with this.

Also if you could recommend a website or book that would help me brush
up on my programming skills I would truly appreciate it.

Thank you
LeeLee


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Comparing info between worksheets

the code coul;d be simplified a little bit. You don't need to test the
account names are different. Just copy the account name from Current Account
to Main Accounts.

Sub checkaccounts()

Sheets("Current accounts").Activate
LastRowCurrent = Sheets("Current accounts").Cells(Rows.Count, "D"). _
End(xlUp).Row

Set searchrange = Sheets("Current accounts"). _
Range(Cells(1, "D"), Cells(LastRowCurrent, "D"))

LastRowMain = Sheets("Main accounts").Cells(Rows.Count, "C"). _
End(xlUp).Row
Sheets("Main accounts").Activate
Set MainRange = Sheets("Main accounts"). _
Range(Cells(1, "C"), Cells(LastRowCurrent, "C"))

For Each cell In MainRange

Set c = searchrange.Find(cell, LookIn:=xlValues)
If Not c Is Nothing Then

If Sheets("Main accounts").Cells(cell.Row, "A") < _
Sheets("Current accounts").Cells(c.Row, "A") Then

Sheets("Main accounts").Cells(cell.Row, "A") = _
Sheets("Current accounts").Cells(c.Row, "A")

End If
Sheets("Main accounts").Cells(cell.Row, "E") = _
Sheets("Current accounts").Cells(c.Row, "G")

End If


Next cell


" wrote:

I could really use some help with a macro. It has been several years
since I did any macro programming and I feel completely lost.

I have recently volunteered my services to the local waterboard to
help them with their books. They are really a mess. One Excel file
has a worksheet with all the original water accounts then a second
worksheet that has all the current billing information, this account
is always updated. The problem is that no one ever updated the Main
Accounts worksheet or otherwise known as the Original accounts
worksheet.


So here is the problem:

Worksheet that is named "Main accounts"
Columns A: Person's name, Column C: Account number Column E:
Address

Worksheet that is named "Current accounts"
Column A: Person's name, Column D: Account numbers Column G:
Address

What I was trying to do unsuccessfully was create a macro that would
go through the worksheet named "Main accounts" check the account
numbers in Column C (Account number column) and look at the name that
is in Column A for that account number.

It would then compare the name that is assigned to the account number
with the name in the worksheet "Current accounts" and if the name was
different it would then put the current name for that account number
on the Main accounts worksheet.

One extra part if possible would be to add the correct address from
the worksheet named "Current accounts" to the address column on the
"Main accounts" worksheet in column E.

One of my fears is that someone might have added accounts to the
Current worksheet and not include it on the Main worksheet. I would
really appreciate some help with this.

Also if you could recommend a website or book that would help me brush
up on my programming skills I would truly appreciate it.

Thank you
LeeLee


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
Comparing info on 2 spreadsheets Jenn Excel Worksheet Functions 1 May 2nd 08 04:22 PM
Comparing Two Columns on Two Worksheets and then Adding New Info. JohnHB Excel Programming 2 April 10th 07 03:40 PM
Comparing info LMB New Users to Excel 4 July 22nd 06 01:01 PM
Comparing files and extracting info. Otillio Excel Worksheet Functions 8 December 7th 05 01:06 AM
Comparing worksheets (extra info) Mark Excel Programming 0 April 9th 04 08:26 PM


All times are GMT +1. The time now is 01:40 AM.

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

About Us

"It's about Microsoft Excel"