How to Apply Range of Formulas to Each Row in 100 Worksheets

johnmeyer

New Member
Joined
Oct 23, 2011
Messages
46
Office Version
  1. 2007
Platform
  1. Windows
I have 100 worksheets from a doctor's office. Each row is data from a patient visit. Each cell in a row contains string data about the patient (name, blood pressure, etc.) as well as the date of the exam, diagnositcs, etc.

I want to create 100 new worksheets, but with some fairly basic manipulations performed on each cell. For instance, I want to separate the patient's name so that there is a cell with just the first name, and a cell with just the last name. I want to delete the word "DATE" which precedes the actual date in each cell. There will still be one row per patient visit, but there will me more columns (since I'm separating patient name into firstname/lastname).

I want each final worksheet to have string data, just like the source worksheet, and not have any formulas or references to the original worksheets.

All of this is very simple to do with formulas, and if I only had one worksheet, I'd insert various columns and create the formulas needed to do the work. I'd then "copy/paste special" to copy the results to the columns in the new worksheet, putting the results into columns in a different column order than in the original worksheet.

But, I have 100 worksheets.

I am using Excel 2003. I am very knowledgeable about how to use Excel, and reasonably proficient with VBA.

Question: Can anyone recommend a simple approach to solve this problem?

The solution I am going to try, if I don't get a better idea here, is to create a worksheet with a macro which prompts the user for the worksheet name of the first worksheet. I was then going to have the first row be the column names of the source worksheet, but in the order I want them to appear in the final worksheet. Below that, I was going to put the formulas for parsing each of these columns. And, below that, I was going to put the results of these formulas for the first row in the source worksheet.

The idea here is that I can modify the column order by simply putting different column letters in this template worksheet, and I can modify my parsing logic by changing the formulas.

However, this leads to my second and final question.

If what I outline is a sensible approach, is there a way in which VBA can use formulas contained in a cell in a spreadsheet, and apply them to a range?

This is a crude example of what I'm trying to do. The formulas are mostly bogus, just to indicate the idea, and I'm not using the file name or column letters to extract data. The key thing is that I want to apply the formulas in B5:H5 to the columns from the original spreadsheet, as shown by the column letters in row 3. I want to do this for every row in the source worksheet, and output the results to a new worksheet.

http://dl.dropbox.com/u/1561578/test.xls

If this is valid, my main stumbling block is knowing a way for VBA to use the formulas shown in B5:H5. I know I can hard-code those formulas in VBA, but I want the flexibility and interactivity of being able to modify them within the template and immediately see the results.


Thanks!!
 
I am a little new in using this forum and also just used MrExcelHTML for the first time and thought I read that I couldn't use the preview function. Thus, I posted and then started making changes, but ran afoul of the ten minute limit on changes (good rule, BTW).

So here's one last bit of information.

The letters in row 4 are used to select columns from Sheet1 in the Workbook specified in cell B1. The macro to open that workbook is activated by a button (not shown in this HTML). The formulas in row 6 are used to modify the contents of each source cell. Thus, the spreadsheet lets you rearrange columns and change the contents of the source worksheet.

I placed a spinner control in cell B1 so you can rapidly "scroll" through the source data and see the results of the parsing formulas in row 6.

When everything is the way you want, you execute the "Extract Data" macro (which is activated by another button, also not shown in this HTML version). This walks through every row of the source XLS workbook and places the results from row 6 into a new workbook, starting with cell A1 in that new workbook.
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Thanks for sharing. Looks good!

Utilizing the worksheet itself, as opposed to strictly VBA, was a pretty slick idea. Really takes advantage of a few of the things Excel excels at--ease of editing and instant results.

As far as dealing with those non-standard names-- the Pareto Principle is alive and well, indeed!
 
Upvote 0

Forum statistics

Threads
1,223,277
Messages
6,171,148
Members
452,382
Latest member
RonChand

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