VBA – 然后在列C中对行进行计数,然后用等式填充列A,B和P.

我有5列。 C列“账户”和D列“人员”是我的数据集。

我想使用VBA来查看我有多less行数据,然后在1)列E“连接”与“帐户”和“员工”串联填充行数在2)列A和B与我有一个INDEX-MATCH方程。

..我试图画出我的列下面,但它没有格式化的方式,我希望是…对不起

Owner | Comment | Account | Employee | Concatenate Jay | Done | JSMA1 | Sally | JSMA1 Sally Will | Not Done| KLLM4 | Jack | KLLM4 Jack Ken | Done | BM3R1 | Sam | BM3R1 Sam 

有任何想法吗?

尝试这个:

 Option Explicit Public Sub fillRanges() Dim ur As Range, hdr As Range, conCol As Variant, lRow As Long Dim ownCol As Variant, comCol As Variant Dim actCol As Variant, empCol As Variant Set ur = Sheet1.UsedRange ' minimal range Set hdr = ur.Rows(1) ' header row lRow = ur.Rows.Count ' last row With Application ownCol = .Match("Owner", hdr, 0) comCol = .Match("Comment", hdr, 0) actCol = .Match("Account", hdr, 0) empCol = .Match("Employee", hdr, 0) conCol = .Match("Concatenate", hdr, 0) End With If Not IsError(ownCol) And _ Not IsError(comCol) And _ Not IsError(actCol) And _ Not IsError(empCol) And _ Not IsError(conCol) _ Then With ur .Range(.Cells(2, ownCol), .Cells(lRow, ownCol)) = "INDEX-MATCH equation 1" .Range(.Cells(2, comCol), .Cells(lRow, comCol)) = "INDEX-MATCH equation 2" .Range(.Cells(2, conCol), .Cells(lRow, conCol)).Formula = _ "=INDIRECT(ADDRESS(ROW()," & actCol & ")) & "" "" & " & _ " INDIRECT(ADDRESS(ROW(), " & empCol & "))" End With End If End Sub