简体   繁体   English

根据另一个工作簿中的单元格值运行一个过程

[英]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.

相关问题 基于另一个工作簿中的单元格值自动筛选 - Autofilter based on a cell values in another workbook 链接到基于另一个单元格的外部工作簿 - Link to external workbook based on another cell 将单元格值从一个工作簿复制到另一个工作簿 - Copying cell values from one Workbook into another 从另一个工作簿将单元格值导入到工作表 - Importing Cell values to Sheet from another workbook VBA:查找文件并将单元格值从一个工作簿中的列复制到另一个根据条件? - VBA: find file and copy cell values from column in one workbook to another based on condition? VBA进行故障排除,根据两个条件将一个工作簿中的一个单元格复制到另一个工作簿中的另一个单元格 - VBA troubleshoot, copy one cell in one workbook to another cell in another workbook based on two criteria VBA 运行脚本,用于当另一个工作簿中的特定单元格发生更改时 - VBA running script for when a specific cell in another workbook changes 根据 Workbook1 中单元格值中的单元格值筛选 Workbook2 中的数据 - Filter Data in Workbook2 based on the cell value in cell values in Workbook1 根据单元格值自动过滤(或循环)并复制到另一个工作簿 - Autofilter (or loop) and copy to another workbook based on Cell Value 基于单元格值循环遍历另一个工作簿中的范围 - Loop Through Ranges in Another Workbook Based on Cell Value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM