Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Excel macro problem with copy and fill down

Posted on 2011-02-24
12
Medium Priority
?
537 Views
Last Modified: 2012-05-11
I have included 2 workbooks and two macros. One is the database (wb1) and the other (wb2) is where the data is copied to. The macros copy the latest data in WB1 into WB2 by comparing the last rows and filling down the new data.
If you run the macros you will see that the EURUSD macro copies the data correctly whilst the AUDUSD macro does not. In the latter case it copies the data by adding 1 to each row.
I actually have about twenty macros that all work; only the AUDUSD does not but I cannot found out where the mistake is. As far as I can see the macros are identical.

Can you help please?
Thanks
CC
ub AUDUSD()

Dim Lastrow1 As Long, Lastrow2 As Long, Lastrow3 As Long, i As Long, rowtouseforAutofill As Long
Lastrow1 = ThisWorkbook.Sheets("AUDUSD").Range("A65536").End(xlUp).Row
Lastrow2 = Workbooks("wb2").Sheets("audusd").Range("A65536").End(xlUp).Row
rowtouseforAutofill = IIf(Lastrow1 < Lastrow2, Lastrow1, Lastrow2)
Workbooks("wb2").Sheets("audusd").Activate
Workbooks("wb2").Sheets("audusd").Rows(rowtouseforAutofill).AutoFill Destination:=Rows(Lastrow1 & ":" & Lastrow2)



End Sub

Sub EURUSD()

Dim Lastrow1 As Long, Lastrow2 As Long, Lastrow3 As Long, i As Long, rowtouseforAutofill As Long
Lastrow1 = ThisWorkbook.Sheets("EURUSD").Range("A65536").End(xlUp).Row
Lastrow2 = Workbooks("wb2").Sheets("eurusd").Range("A65536").End(xlUp).Row
rowtouseforAutofill = IIf(Lastrow1 < Lastrow2, Lastrow1, Lastrow2)
Workbooks("wb2").Sheets("eurusd").Activate
Workbooks("wb2").Sheets("eurusd").Rows(rowtouseforAutofill).AutoFill Destination:=Rows(Lastrow1 & ":" & Lastrow2)



End Sub

Open in new window

wb2.xlsm
WB1.xls
0
Comment
Question by:CC10
  • 5
  • 4
  • 3
12 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 34976863
You will have to attach a working copy of the files. The files already attached are not working copies - the sheet names are not as per the Macro requirement. Without the working copy which is giving you the problem it would be difficult to detect what is going wrong.

Saqib
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 34976873
You will have to attach a working copy of the files. The files already attached are not working copies - the sheet names are not as per the Macro requirement. Without the working copy which is giving you the problem it would be difficult to detect what is going wrong.

Saqib
0
 
LVL 18

Expert Comment

by:Curt Lindstrom
ID: 34977309
As Saqib says, it's very difficult to determine your problem without the working copies. However, two odd things about the macros:

1. Lastrow3 is declared in both macros but never used
2. The empty module in Wb1 seems to indicate that the macros resides in this workbook. This means that Lastrow1 and Lastrow2 will always be identical.

Curt
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 18

Expert Comment

by:Curt Lindstrom
ID: 34977497
The second line should have read:
The empty module in Wb2 seems to indicate that the macros resides in this workbook. This means that Lastrow1 and Lastrow2 will always be identical.

Curt
0
 

Author Comment

by:CC10
ID: 34977809
My apologies. I have included the two workbooks which I have saved in the C drive. I have deleted the "last row 3" in the macros. The real macros are more complex but if the data download does not work, then all the rest is useless.
Sub AUDUSD()

Dim Lastrow1 As Long, Lastrow2 As Long, i As Long, rowtouseforAutofill As Long
Lastrow1 = ThisWorkbook.Sheets("AUDUSD").Range("A65536").End(xlUp).Row
Lastrow2 = Workbooks("wb2").Sheets("audusd").Range("A65536").End(xlUp).Row
rowtouseforAutofill = IIf(Lastrow1 < Lastrow2, Lastrow1, Lastrow2)
Workbooks("wb2").Sheets("audusd").Activate
Workbooks("wb2").Sheets("audusd").Rows(rowtouseforAutofill).AutoFill Destination:=Rows(Lastrow1 & ":" & Lastrow2)



End Sub

Sub EURUSD()

Dim Lastrow1 As Long, Lastrow2 As Long, i As Long, rowtouseforAutofill As Long
Lastrow1 = ThisWorkbook.Sheets("EURUSD").Range("A65536").End(xlUp).Row
Lastrow2 = Workbooks("wb2").Sheets("eurusd").Range("A65536").End(xlUp).Row
rowtouseforAutofill = IIf(Lastrow1 < Lastrow2, Lastrow1, Lastrow2)
Workbooks("wb2").Sheets("eurusd").Activate
Workbooks("wb2").Sheets("eurusd").Rows(rowtouseforAutofill).AutoFill Destination:=Rows(Lastrow1 & ":" & Lastrow2)



End Sub

Open in new window

wb2.xlsm
WB1.xls
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 1000 total points
ID: 34977950
The AUDUSD sheet does not work as expected because it contains values which are incremented by 1 through the "Autofill" method.

On the other hand the EURUSD sheet has formulas which refer to the other workbook and the Autofill increments the formula by 1 thus giving the desired results.

Saqib
0
 
LVL 43

Assisted Solution

by:Saqib Husain, Syed
Saqib Husain, Syed earned 1000 total points
ID: 34977983
You need to change the AUDUSD sheet to contain formulas similar to the EURUSD worksheet and then you can run the macro as desired.
0
 

Author Comment

by:CC10
ID: 34978117
Staring at me in the face and I didn't notice it.  I will split the points as the solutions arrived at the same time. I hope thats is OK.

Thank you for your help.
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 34978137
>>>I will split the points...

It really does not matter as both the comments from me.... which further strengthens your comment Staring at me in the face and I didn't notice it....

;-)

Cheers

Thanks for the points

Saqib
0
 

Author Comment

by:CC10
ID: 34978250
Saqib,

it is what happens to you when you get over 35...............

Best,
Chris
0
 
LVL 18

Expert Comment

by:Curt Lindstrom
ID: 34978280
Both halves of Saquib deserved to split the points! I missed out making any useful contribution enjoying my dinner and a glass of wine here down under in Oz while it all happened  :-)

Curt
0
 

Author Comment

by:CC10
ID: 34978666
Sorry Curt. I will be back soon with another moronic question.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Quickbooks hosting can do wonders to your enterprise but considering the points elaborated in the article which will help you to better analyze the outcomes. So scan your business, its needs and then move to the new world of limitless benefits.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question