如何从两个不同的工作表匹配相同的名称后得到%值

我想知道如果有人可以帮我解决以下问题。 以前有人帮助我在同一个工作表上获得dctest / In值的百分比 。 但现在,我需要做同样的事情,但在不同的工作表上。

说Sheet1

在这里输入图像说明

这是复制Sheet1(1)后采取%

在这里输入图像说明

Sub marco1() 'start making Sheet1 into % '~~> Add/Remove the text here which you want to ignore Excludetext = "In,test1,test2,test3,test4,test5,test6" MyArray = Split(Excludetext, ",") Set ws = Sheets("Sheet1") LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row 'Set Column B into % For i = 1 To LastRow boolContinue = True For j = 0 To UBound(MyArray) SearchText = UCase(Trim(MyArray(j))) If UCase(Trim(ws.Range("A" & i).Value)) = SearchText Then boolContinue = False Exit For End If Next j If boolContinue = True Then With Range("B" & i) .Formula = _ "=OFFSET(INDIRECT(ADDRESS(INDEX(MATCH(A" & i & _ ",$A$1:$A$45,0),1,0),1,1,1,'Duplicated_Sheet1')),0,1)/$B$5" .NumberFormat = "0.00%" End With End If Next i End sub 

在公式中显示出一些错误,我是否在公式中犯了错误? 先谢谢你!

这是你正在尝试?

尝试和testing

 Option Explicit Sub Sample() Dim ws As Worksheet Dim wsData As String Dim SearchText As String, Excludetext As String Dim LastRow As Long, i As Long, j As Long Dim MyArray() As String Dim boolContinue As Boolean '~~> Add/Remove the text here Excludetext = "In,Test1,Test2,Test3,Test4,Test5,Test6" '~~> Change this to the relevant sheetname which has the data wsData = "Sheet1" MyArray = Split(Excludetext, ",") Set ws = Sheets("Sheet2") LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row For i = 1 To LastRow boolContinue = True For j = 0 To UBound(MyArray) SearchText = MyArray(j) If ws.Range("A" & i).Value = SearchText Then boolContinue = False Exit For End If Next j If boolContinue = True Then With ws.Range("B" & i) .Formula = _ "=OFFSET(INDIRECT(ADDRESS(INDEX(MATCH(A" & i & _ "," & wsData & "!$A$1:$A$11,0),1,0),1,1,TRUE,""" & _ wsData & """)),0,1)/" & wsData & "!B1" .NumberFormat = "0.00%" End With End If Next i End Sub 

当使用ADDRESS()为另一个单元格中的单元格时,您必须指定其他参数。

直接从Excel的帮助

ADDRESS函数的语法

 ADDRESS(row_num, column_num, [abs_num], [a1], [sheet_text]) 

其中[sheet_text]是我们所指的表单的名称。 我会build议阅读更多关于它在Excel帮助。

这是dctest的实际公式

 =OFFSET(INDIRECT(ADDRESS(INDEX(MATCH(A7,Sheet1!$A$1:$A$11,0),1,0),1,1,TRUE,"Sheet1")),0,1)/Sheet1!B1 

HTH

希德