1 Attachment(s)
Re: Excel data manipulation
dear,
The fastest way is to work with 2 array: don't jump to the sheets 1 - 2 - 3 - 1 - 2 -.....
We use=
one with the 2e sheet data = username - userID
and one with the results = ItemID - UserID
how it works:
Load the data of the 2e sheet in the array.
Loop the data in the 1e sheet and check with the array from the 2e sheet = write the results in the array for the 3e sheet.
Dump the 2e array in the 3e sheet.
This is the code=
###########################################
Option Explicit
Type Name_UserID
Name As String
UserID As String
End Type
Type ItemID_UserID
ItemID As String
UserID As String
End Type
Sub Macro1()
Dim ArrayNameUserID() As Name_UserID
Dim ArrayItemIDUserID() As ItemID_UserID
Dim i As Integer
'§ FILL ARRAY ArrayNameUserID
'§ ==========================
Sheet2.Activate
Range("a2").Activate
'§ fill the 1e record
ReDim ArrayNameUserID(0)
ArrayNameUserID(UBound(ArrayNameUserID)).Name = ActiveCell.Value
ArrayNameUserID(UBound(ArrayNameUserID)).UserID = ActiveCell.Offset(0, 1).Value
'§ go to the next record
ActiveCell.Offset(1, 0).Activate
'§ load all other records
Do While ActiveCell.Value <> ""
ReDim Preserve ArrayNameUserID(UBound(ArrayNameUserID) + 1)
ArrayNameUserID(UBound(ArrayNameUserID)).Name = ActiveCell.Value
ArrayNameUserID(UBound(ArrayNameUserID)).UserID = ActiveCell.Offset(0, 1).Value
'§ go to the next record
ActiveCell.Offset(1, 0).Activate
Loop
'§ check all records and FILL ARRAY ArrayItemIDUserID
'§ ==================================================
Sheet1.Activate
Range("a2").Activate
'§ fill the 1e record
ReDim ArrayItemIDUserID(0)
ArrayItemIDUserID(UBound(ArrayItemIDUserID)).ItemID = ActiveCell.Offset(0, 1).Value
'§ find the userID
For i = LBound(ArrayNameUserID) To UBound(ArrayNameUserID)
If ActiveCell.Value = ArrayNameUserID(i).Name Then _
ArrayItemIDUserID(UBound(ArrayItemIDUserID)).UserID = ArrayNameUserID(i).UserID
Next
'§ go to the next record
ActiveCell.Offset(1, 0).Activate
'§ load all other records
Do While ActiveCell.Value <> ""
ReDim Preserve ArrayItemIDUserID(UBound(ArrayItemIDUserID) + 1)
ArrayItemIDUserID(UBound(ArrayItemIDUserID)).ItemID = ActiveCell.Offset(0, 1).Value
'§ find the userID
For i = LBound(ArrayNameUserID) To UBound(ArrayNameUserID)
If ActiveCell.Value = ArrayNameUserID(i).Name Then _
ArrayItemIDUserID(UBound(ArrayItemIDUserID)).UserID = ArrayNameUserID(i).UserID
Next
'§ go to the next record
ActiveCell.Offset(1, 0).Activate
Loop
'§ dump the results from ARRAY ArrayItemIDUserID
'§ =============================================
Sheet3.Activate
Range("a2").Activate
For i = LBound(ArrayItemIDUserID) To UBound(ArrayItemIDUserID)
ActiveCell.Value = ArrayItemIDUserID(i).ItemID
ActiveCell.Offset(0, 1).Value = ArrayItemIDUserID(i).UserID
ActiveCell.Offset(1, 0).Activate
Next
End Sub
###########################################
See also the attachment.
br,
Re: Excel data manipulation
Who can READ that? Please go back and add CODE TAGS to that mess!