Macro creates empty rows

DSLA

Active Member
Joined
Jun 6, 2005
Messages
301
Hello everyone.

In one file we have a macro that collects data from a datafile(other excel) according to the customer number(s).

Here is the code: (the code runs through several fields and gets the sales data according to the customer number in the cell (Range. "D16") and collects it to the CUSTOMER_DATA-sheet)

Dim varFileName1 As String
varFileName1 = Application.ActiveWorkbook.Name
Workbooks.Open Filename:="C:\DATAFILE.XLS"
Dim WB1 As Workbook
Set WB1 = ActiveWorkbook
With WB1.Sheets("DATASHEET")
With .Range("A1:Z65500")
Windows(varFileName1).Activate
.AutoFilter Field:=1, Criteria1:=Sheets("INFOCARD").Range("D16")
.Copy Sheets("CUSTOMER_DATA").Range("A1")
.AutoFilter
End With
End With
WB1.Close savechanges:=False
End If


The problem is that now the code collect the data, but for some reason created 32 000 empty cells also (that is the amount of rows that the DATAFILE.XLS has rows). And the filesize goes up from under 200kb to 2500kb.

Before the code just got the values it found on the search, but now it creates also the empty cell.

Can anyone help me with this one? Please ask if something wasn't clear.

Thanx in advance.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Both links work, just select Save target as, if the straight clicking of the link doesn't work.
 
Upvote 0
Sure this would be possible, but it is quite a project and a half(takes a lot of time) to change them all.

Either way you go, it's going to take a lot of time. I was thinking along the lines of maybe if all the workbooks were in one folder then looping through each and deleting the module with the macro in it and adding the revised/edited one. However, I'm curious is there a reason you have the same macro in 1500 workbooks? Couldn't you just create one workbook with the macro and then run it on the others?
 
Upvote 0
Either way you go, it's going to take a lot of time. I was thinking along the lines of maybe if all the workbooks were in one folder then looping through each and deleting the module with the macro in it and adding the revised/edited one. However, I'm curious is there a reason you have the same macro in 1500 workbooks? Couldn't you just create one workbook with the macro and then run it on the others?

These are old files and they have been the same for a while, we don't want to update them because of the work it requires, but propably we have to now.
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,183
Members
452,893
Latest member
denay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top