Excel VBA根据唯一记录和工资制作不同的集合
我有以下数据,
Empid Empname salary Company location status
xx Jhon 100 IBM us
x1 Phil 50 IBM us
x2 Karl 30 IBM us
x3 Steve 20 IBM us
x4 jacob 70 Oracle uk
x5 jason 30 Oracle uk
x6 stuart 50 Oracle uk
zz jay 150 Oracle uk
x10 Steve1 20 IBM ind
x9 Steve2 20 IBM nj
我必须根据公司和位置分隔记录。所以我会得到下面两组记录。
第一组
Empid Empname salary company Location status
xx Jhon 100 IBM us
x1 Phil 50 IBM us
x2 Karl 30 IBM us
x3 Steve 20 IBM us
第二组
Empid Empname salary company Location status
x4 jacob 70 Oracle uk
x5 jason 30 Oracle uk
x6 stuart 50 Oracle uk
zz jay 150 Oracle uk
在上面的组中XX,zz是主记录。我检查 x1+x2+x3 是否 =xx 工资。如果相等,则我在该集的列状态中写入匹配项,否则我将忽略。原始工作表中的最后两行应忽略,因为它没有主记录。
Sub Tester()
Const COL_COMP As Integer = 4
Const COL_LOC As Integer = 5
Const VAL_DIFF As String = "XXdifferentXX"
Dim d As Object, sKey As String
Dim rw As Range, opt As String, rngData As Range
Dim rngCopy As Range
Dim FirstPass As Boolean
With Sheet1.Range("A1")
Set rngData = .CurrentRegion.Offset(1).Resize( _
.CurrentRegion.Rows.Count - 1)
End With
Set rngCopy = Sheet2.Range("A2")
Set d = CreateObject("scripting.dictionary")
FirstPass = True
redo:
For Each rw In rngData.Rows
sKey = rw.Cells(COL_COMP).Value & "<>" & _
rw.Cells(COL_LOC).Value
'Here i have to make different sets of data.
Next rw
If FirstPass Then
FirstPass = False
GoTo redo
End If
End Sub
I have below data
Empid Empname salary Company location status
xx Jhon 100 IBM us
x1 Phil 50 IBM us
x2 Karl 30 IBM us
x3 Steve 20 IBM us
x4 jacob 70 Oracle uk
x5 jason 30 Oracle uk
x6 stuart 50 Oracle uk
zz jay 150 Oracle uk
x10 Steve1 20 IBM ind
x9 Steve2 20 IBM nj
I have to separate records based on company and location. So I will get below two sets of records.
First Set
Empid Empname salary company Location status
xx Jhon 100 IBM us
x1 Phil 50 IBM us
x2 Karl 30 IBM us
x3 Steve 20 IBM us
Second set
Empid Empname salary company Location status
x4 jacob 70 Oracle uk
x5 jason 30 Oracle uk
x6 stuart 50 Oracle uk
zz jay 150 Oracle uk
In above sets XX,zz are master records. I check if x1+x2+x3 =xx salary. If it is equal then I write as matched in the column status for that set otherwise I ignore. Last two rows in original sheets should ignore because it does not have a master record.
Sub Tester()
Const COL_COMP As Integer = 4
Const COL_LOC As Integer = 5
Const VAL_DIFF As String = "XXdifferentXX"
Dim d As Object, sKey As String
Dim rw As Range, opt As String, rngData As Range
Dim rngCopy As Range
Dim FirstPass As Boolean
With Sheet1.Range("A1")
Set rngData = .CurrentRegion.Offset(1).Resize( _
.CurrentRegion.Rows.Count - 1)
End With
Set rngCopy = Sheet2.Range("A2")
Set d = CreateObject("scripting.dictionary")
FirstPass = True
redo:
For Each rw In rngData.Rows
sKey = rw.Cells(COL_COMP).Value & "<>" & _
rw.Cells(COL_LOC).Value
'Here i have to make different sets of data.
Next rw
If FirstPass Then
FirstPass = False
GoTo redo
End If
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果有人面临类似问题,请使用以下解决方案
问候,
拉吉
use below solution if anyone facing for similar kind of problem
Regards,
Raj