Solved

Excel macro problem with copy and fill down

Posted on 2011-02-24
12
534 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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!

 
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 250 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 250 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Outlook Free & Paid Tools
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

734 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