Morgan Moore
New Member
Hi all!
I am new to this forum...my first time in any type of excel forum, so I ask that you please forgive my ignorance! I am here to learn. I have moderate skills in excel and VBA, but self taught. This may be too much information, but here is my background/question:
-I have created a workbook to generate reports of certain data.
-"Sample Info", "List Form", and "Report Template" are the tabs I am working with.
-"Sample Info" contains a list of sample numbers and product names entered by a UserForm.
-"List Form" is a list of data copied from another tab and cleaned up so that I can use INDEX and MATCH
-"Report Template" is what it sounds like. It has formulas built in the template to reference "Sample Info" (to pull product name and sample number to the report), and "List Form" to find data from the list based on two criteria, and paste it into the report.
-The tricky part is that I wrote a macro to find the sample numbers in the "Sample Info" tab, and use the "Report Template" to generate a report for each sample.
-THE PROBLEM...every time a report is generated, the formula range is adjusted automatically, and therefore some data is missed with a new generation. Here the formula within "Report Template":
{=INDEX('List Form'!$V$2:$V$500,MATCH(1,IF('List Form'!$Q$2:$Q$500=--$I$2,IF('List Form'!$B$2:$B$500=$D8,1)),0))}
I run the macro and it changes to:
{=INDEX('List Form'!$V$1:$V$422,MATCH(1,IF('List Form'!$Q$1:$Q$422=--$I$2,IF('List Form'!$B$1:$B$422=$D8,1)),0))}
And again:
{=INDEX('List Form'!$V$1:$V$352,MATCH(1,IF('List Form'!$Q$1:$Q$352=--$I$2,IF('List Form'!$B$1:$B$352=$D8,1)),0))}
Here is the code to generate new tabs based on list of sample numbers:
Sub NewTab()
'This finds the sample numbers from the sample info tab and creates new tabs with the report format and renames the tabs as the sample number
hh = Sheets("SampleInfo").Cells(Rows.Count, 1).End(xlUp).Row - 1
Sheets("Report Template").Select
Application.DisplayAlerts = False
nn = 0
Do Until nn = hh
Sheets("Report Template").Select
Sheets("Report Template").Copy After:=Sheets(6 + nn)
ActiveSheet.Name = Sheets("SampleInfo").Range("C1").Cells(2 + nn, 1).Value
nn = nn + 1
Loop
End Sub
***I need the formula range in to stay constant at 2:500 (the formula that is in green text) every time I run the macro. This is in the case that someone notices a mistake and needs to regenerate the report.
Thank you for your help in advance! I did not want to upload the spreadsheet yet, unless this is a simple fix, which I am hoping is the case.
Morgan
I am new to this forum...my first time in any type of excel forum, so I ask that you please forgive my ignorance! I am here to learn. I have moderate skills in excel and VBA, but self taught. This may be too much information, but here is my background/question:
-I have created a workbook to generate reports of certain data.
-"Sample Info", "List Form", and "Report Template" are the tabs I am working with.
-"Sample Info" contains a list of sample numbers and product names entered by a UserForm.
-"List Form" is a list of data copied from another tab and cleaned up so that I can use INDEX and MATCH
-"Report Template" is what it sounds like. It has formulas built in the template to reference "Sample Info" (to pull product name and sample number to the report), and "List Form" to find data from the list based on two criteria, and paste it into the report.
-The tricky part is that I wrote a macro to find the sample numbers in the "Sample Info" tab, and use the "Report Template" to generate a report for each sample.
-THE PROBLEM...every time a report is generated, the formula range is adjusted automatically, and therefore some data is missed with a new generation. Here the formula within "Report Template":
{=INDEX('List Form'!$V$2:$V$500,MATCH(1,IF('List Form'!$Q$2:$Q$500=--$I$2,IF('List Form'!$B$2:$B$500=$D8,1)),0))}
I run the macro and it changes to:
{=INDEX('List Form'!$V$1:$V$422,MATCH(1,IF('List Form'!$Q$1:$Q$422=--$I$2,IF('List Form'!$B$1:$B$422=$D8,1)),0))}
And again:
{=INDEX('List Form'!$V$1:$V$352,MATCH(1,IF('List Form'!$Q$1:$Q$352=--$I$2,IF('List Form'!$B$1:$B$352=$D8,1)),0))}
Here is the code to generate new tabs based on list of sample numbers:
Sub NewTab()
'This finds the sample numbers from the sample info tab and creates new tabs with the report format and renames the tabs as the sample number
hh = Sheets("SampleInfo").Cells(Rows.Count, 1).End(xlUp).Row - 1
Sheets("Report Template").Select
Application.DisplayAlerts = False
nn = 0
Do Until nn = hh
Sheets("Report Template").Select
Sheets("Report Template").Copy After:=Sheets(6 + nn)
ActiveSheet.Name = Sheets("SampleInfo").Range("C1").Cells(2 + nn, 1).Value
nn = nn + 1
Loop
End Sub
***I need the formula range in to stay constant at 2:500 (the formula that is in green text) every time I run the macro. This is in the case that someone notices a mistake and needs to regenerate the report.
Thank you for your help in advance! I did not want to upload the spreadsheet yet, unless this is a simple fix, which I am hoping is the case.
Morgan
