I have a workbook that is acting as a database. Every time we get results back I can easily upload everything to a worksheet named database, and then recall all data into a nicely organised table on my worksheet named OilSamplingResults by typing in a units serial number on the results page. I'm trying to setup a page called ExportList, wherein I can type the unit serial numbers in column A, and the equipment ID in column B. The macro copies the serial number into my results page to obtain all the numbers, copies the page (now called OilSampleResults (2)), 'Flattens' the newly created page by doing a special paste of just values, and then moves the sheet to a different workbook called TestFile, and renames the worksheet based on the Equipment ID column.
This portion works fine but I'm having two main issues.
The export to workbook ideally could be a variation of names based on job (My general format is 'report name - client - brief job description'). That being said, when I hit export, it only needs to go to that one file, but the next job and group of samples will be a different file name. Not sure if there's a way I could simply have a "File Name" spot at the top of my ExportList page that replaces "TestFile" in my code above. I've tried a few ways to dim a variable of sorts but my VBA is only so-so and I keep getting errors.
The second problem is For Each loops. Any given job could have between 1-60 pieces of equipment being sampled. My hope is to be able to be able to just type in the serial numbers and ID's once.
VBA Code:
Sub ExportData()
Dim Database As Workbook
Dim TestFile As Workbook
Dim OilSamplingResults As Worksheet
Dim ExportList As Worksheet
ScreenUpdating = False
Sheets("ExportList").Range("A2").Copy Sheets("OilSamplingResults").Range("G5")
Sheets("OilSamplingResults").Copy After:=Sheets("OilSamplingResults")
Sheets("OilSamplingResults (2)").Range("A1:BN45").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("OilSamplingResults (2)").Move After:=Workbooks("TestFile").Sheets("Master")
Workbooks("TestFile").Sheets("OilSamplingResults (2)").Name = Workbooks("Database").Sheets("ExportList").Range("B2")
Workbooks("Database").Sheets("ExportList").Activate
ScreenUpdating = True
End Sub
This portion works fine but I'm having two main issues.
The export to workbook ideally could be a variation of names based on job (My general format is 'report name - client - brief job description'). That being said, when I hit export, it only needs to go to that one file, but the next job and group of samples will be a different file name. Not sure if there's a way I could simply have a "File Name" spot at the top of my ExportList page that replaces "TestFile" in my code above. I've tried a few ways to dim a variable of sorts but my VBA is only so-so and I keep getting errors.
The second problem is For Each loops. Any given job could have between 1-60 pieces of equipment being sampled. My hope is to be able to be able to just type in the serial numbers and ID's once.