|
-
Oct 9th, 2005, 12:15 PM
#1
Thread Starter
Junior Member
Excel: copy data between sheets
Hi all,
I have 2 sheets "sheet1" and "sheet2". I ask from a user to copy the cell range A5:F10 from "sheet1" to the same cell range of the "sheet2". I need a code that checks if the user movements are correct or not.
Please help!
Thanks in advance.
-
Oct 9th, 2005, 12:16 PM
#2
Re: Excel: copy data between sheets
Hi,
Forgive me if I misunderstand, but why not copy it yourself? Is it a training program or something? You can very easily copy the cells from one sheet to another.
zaza
-
Oct 10th, 2005, 02:28 AM
#3
Thread Starter
Junior Member
Re: Excel: copy data between sheets
Thanks for your answer.
Yes I am trying to make a training program (VB6) that checks the correct movements of a user actions. My problem is that i can't find the right references between 2 sheets, so I can solve it.
-
Oct 10th, 2005, 08:15 AM
#4
Frenzied Member
Re: Excel: copy data between sheets
kabilliu:
This is a snippet that will get you started. I threw it together quickly, but it does run. Try to work on it and post your code if you have problems.
Code:
Option Explicit
Sub Macro1()
Dim srcSheet As Worksheet 'Source Sheet
Dim dstSheet As Worksheet 'Destination Sheet
Dim aRange As Range '
Dim aCell As Range
Dim aRow As Long
Dim aCol As Integer
'
Set srcSheet = Sheets("sheet1")
Set dstSheet = Sheets("sheet2")
Set aRange = srcSheet.Range("A5:F10")
For Each aCell In aRange
aRow = aCell.Row
aCol = aCell.Column
'Parameters: what all do we check here?
If aCell = dstSheet.Cells(aRow, aCol) Then
'The cells match
'TEST TEST TEST TEST
MsgBox "Match: "
'END TEST
Else
'The cells do not match
'TEST TEST TEST TEST
MsgBox aCell.Address & Chr(10) & "No Match: "
'END TEST
End If
Next
End Sub
Good Learning and Good Programming!
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Oct 11th, 2005, 02:48 AM
#5
Thread Starter
Junior Member
Re: Excel: copy data between sheets
Thanks for your help.
Your code helps very much and works fine.
I would like to know if is possible to change the loop "For Each ..e.c.c." or use some function, so I can get the total result.
Your code checks the cells on the area (A5:F10) and show me the result (match or not match) for any cell. I prefer the code to check the cells behind and finally show me the result for whole area.
Thanks again
Regards
-
Oct 11th, 2005, 07:03 AM
#6
Frenzied Member
Re: Excel: copy data between sheets
You can set the range in the "Set aRange" statement to whatever you want. I just did that because you wrote:
 Originally Posted by kabilliu
I ask from a user to copy the cell range A5:F10 from "sheet1" to the same cell range of the "sheet2". I need a code that checks if the user movements are correct or not.
I think that English is not your primary language. If so, you are doing pretty good, but I can't understand "so I can get the total result". Are you trying to find the SUM of the range of cells?
Also, please clarify: "I prefer the code to check the cells behind".
My code is just a template for you to work from. You can do whatever you want in place of the two message box statements. After all, you are writing the program. You can set up counters for the number of correct and incorrect answers; you can create a string with a list of the incorrect answers; do whatever you want. Then, between the "Next" and "End Sub" statements, you can put your code to report the results.
Last edited by Webtest; Oct 11th, 2005 at 07:10 AM.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
-
Oct 11th, 2005, 04:38 PM
#7
Thread Starter
Junior Member
Re: Excel: copy data between sheets
Thanks for your interest.
You are right my English is not my primary language and for this reason is not good.
I am sorry for that.
Anyway I retry to explain you what I want.
Your code checks one by one the cells and shows the differences.
I ask if is possible to change the code so checks in background (Behind the scene) the cells and finally show me if the area A5:F5 of the sheet1 is equal or not with area A5:F5 of sheet2 (Not for any cell but for whole area)
Thanks for your time
-
Oct 12th, 2005, 12:24 AM
#8
Addicted Member
Re: Excel: copy data between sheets
I think this is what you're missing:
VB Code:
Dim TheTotal1 As Double, TheTotal2 As Double
'to run the code in the background
Application.ScreenUpdating = False
'to compare sum of the 2 ranges
TheTotal1 = Application.WorksheetFunction.Sum(Sheet1.Range("A5:A10"))
TheTotal2 = Application.WorksheetFunction.Sum(Sheet2.Range("A5:A10"))
If TheTotal1 = TheTotal2 Then
(your code)
End If
'you have to turn it back to true
Application.ScreenUpdating = True
-
Oct 12th, 2005, 01:50 AM
#9
Thread Starter
Junior Member
Re: Excel: copy data between sheets
Thank you very much D-Niss,
This is that I want and works perfectly.
Thanks again!
Regards.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|