Solved

Excel macro problem with copy and fill down

Posted on 2011-02-24
12
530 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 18

Expert Comment

by:Curt Lindstrom
Comment Utility
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
Comment Utility
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 250 total points
Comment Utility
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
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 43

Assisted Solution

by:Saqib Husain, Syed
Saqib Husain, Syed earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
>>>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
Comment Utility
Saqib,

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

Best,
Chris
0
 
LVL 18

Expert Comment

by:Curt Lindstrom
Comment Utility
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
Comment Utility
Sorry Curt. I will be back soon with another moronic question.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now