Solved

Excel macro problem with copy and fill down

Posted on 2011-02-24
12
531 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
 
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

This collection of functions covers all the normal rounding methods of just about any numeric value.
My experience with Windows 10 over a one year period and suggestions for smooth operation
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…

929 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

8 Experts available now in Live!

Get 1:1 Help Now