Tricky Dynamic range problem

smithy99

New Member
Joined
Jul 28, 2006
Messages
5
I am trying to do statistical analysis of more than 500 files. I am trying to automate this with a macro, but I am having a hard time with it.

Each file that I work with changes as far as length goes, so I am trying to write a macro that will use the define names to allow for changes in length.

Note that the only sheet that I am working with is on one sheet only per file.

Presently, I am trying to make a macro to define names, like this:

columnA

refers to: =OFFSET(A.HIS!$M$2,0,0,COUNTA(A.HIS!$M:$M),1)

and when I get down to further along the macro I what to do an analysis of the column:

Application.Run "ATPVBAEN.XLA!Descr", ActiveSheet.Range("columnA"), _
ActiveSheet.Range("$Ap$2:$Ap$12"), "C", False, True

The macro works fine like this, but when I try to be more general like this,
This generality is the whole reason to keep from writing a macro for each specific file.

columnA

refers to: =OFFSET(ActiveSheet!$M$2,0,0,COUNTA(ActiveSheet!$M:$M),1)

I get an error

What can I do to fix this?
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
It looks like your are trying to create a 'named' range in each of the 'more than 500 files', by opening each file (ActiveSheet).

define names, like this: columnA
refers to: =OFFSET(A.HIS!$M$2,0,0,COUNTA(A.HIS!$M:$M),1)

And:
and when I get down to further along the macro I what to do an analysis of the column:

Application.Run "ATPVBAEN.XLA!Descr", ActiveSheet.Range("columnA"), _
ActiveSheet.Range("$Ap$2:$Ap$12"), "C", False, True

It looks like your are running an addin against the data in each open 'ActiveSheet'.

1. Are the 'more than 500 files' in the same folder?
2. Is the data in each file, in the same sheet name, and same beginning address?
3. What is the target range/address (i.e., AP2:AP2) if there is only one row of information?
4. Is there any other data/information in the rows below the range you are looking at?

I have a macro that can be modified that does the following:
The data begins at the same address/row in each file.
The data is variable (number of rows).
It reads the date in each file and lists the:
filename in column A, data 1 in column B, etc.
next row of data in the same format as above (if there is more data). When it reads/finds a blank row, it....
Drops down two rows (leaves a blank row between file names).
And cycles thru the remaining file names in the original list.

It uses code from:
' Function MyName, MyFullName, SheetName
' Excel Hacks, 100 Industrial-Strength Tips & Tools
' David & Raina Hawley
' O'Reilly
' Excel Hack #91
'
Dim strSearchFolderName As String
'=MID(MyFullName(),1,LEN(MyFullName())-LEN(MyName()))
strSearchFolderName = Mid(MyFullName(), 1, Len(MyFullName()) - Len(MyName()))


And code for (available on the WEB):
'Files Collection
'Description
'Collection of all File objects within a folder.
'Remarks
'The following code illustrates how to get a Files collection and iterate the collection using the For Each...Next statement:
'
' Server Downtime v2
' Modified on January 18, 2006 by
' Stanley D. Grom, Jr.

Sub ShowFolderList(folderspec)



The summary sheet is in the same folder as the 'more than 500 files'.
It creates a list of all file names, except the summary worksheet name.
It then lists (one file at a time) in the summary worksheet, in adjacent columns:
filename1, contents from filename1!A2, (contents from filename1!B2),...
filename1, contents from filename1!A3, (contents from filename1!B3),...
filename1, contents from filename1!A4, (contents from filename1!B4),...

filename2, contents from filename2!A2, (contents from filename2!B2),...
filename2, contents from filename2!A3, (contents from filename2!B3),...

and so on.


I am using Windows XP Professional SP3, and Excel 2003 SP2.

Have a great day,
Stan
 
Upvote 0
You can name a range as the following codes:

Code:
ActiveSheet.Range("m2:m" & ActiveSheet.Range("m65536").End(xlUp).Row).Name = "columnA"

Best Regards
 
Upvote 0

Forum statistics

Threads
1,223,171
Messages
6,170,478
Members
452,332
Latest member
The2ndQuest

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