[英]Running a procedure based on cell values in another workbook
I have six different forms, all of which contain the same information but in different places. 我有六种不同的形式,所有形式都包含相同的信息,但是位置不同。 These forms are sent to me by other parties and once I receive them, I open the file, determine which form I am dealing with, then run the appropriate transposition macro to upload the information to my summary workbook.
这些表单是由其他方发送给我的,当我收到它们后,我打开文件,确定要处理的表单,然后运行适当的转置宏将信息上载到我的摘要工作簿中。
I would like to be able to check cells B4, B8, B10, B15 and B20 to ascertain what form I am dealing with, then have the appropriate transposition macro run on its own. 我希望能够检查单元格B4,B8,B10,B15和B20,以确定我要处理的是哪种形式,然后自行运行适当的转置宏。
Can someone please help me set this up? 有人可以帮我设置这个吗?
Right now I have the following: 现在,我有以下内容:
' I use the file path to identify the form that I want to copy information from
Dim FilePath As String
Dim InputTemplate As Workbook
Dim UploadForm As Workbook
Dim Analysis As Worksheet
Dim supplierdata As Worksheet
Dim TemplateType
Set UploadForm = ActiveWorkbook
FilePath = UploadForm.Sheets("Summary").Range("D4").Value
Set InputTemplate = Workbooks.Open(FilePath)
Set Analysis = UploadForm.Sheets("Analysis")
Set supplierdata = InputTemplate.Sheets("Supplier Input Template")
How do I say that if B4.value=Company Name, B8.value=Date, B10.value = Currency... then run the correct transposition macro? 我怎么说,如果B4.value =公司名称,B8.value =日期,B10.value =货币...,然后运行正确的转置宏?
The most-condensed you could do it might be something like: 您能做到的最精简的可能是:
'....
Set supplierdata = InputTemplate.Sheets("Supplier Input Template")
With supplierdata.Columns(2)
If .Cells(4).value = "Company Name" And .Cells(8).Value="Date" _
And .Cells(10).Value = "Currency" Then
'handle this type of form
End If
End With
If you have many of these types of checks to perform, then you could consider using a "metadata-driven" approach, where you list on a worksheet the Ranges and the corresponding content, and loop over that information to detect the type of report. 如果要执行许多此类检查,则可以考虑使用“元数据驱动”方法,在该方法中,您可以在工作表上列出范围和相应的内容,然后遍历该信息以检测报告的类型。 That would be more coding up-front but easier ongoing maintenance once you have it set up.
设置好代码后,可以进行更多的前期编码,但更容易进行后续维护。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.