Find VPA by finding duplicate or non-duplicate rows (common or non-common) on a page and move values to a row on another Excel page :Thank you

bahrami

New Member
Joined
Feb 26, 2022
Messages
14
Office Version
  1. 2007
Platform
  1. Windows
Find VPA by finding duplicate or non-duplicate rows (common or non-common) on a page and move values to a row on another Excel page :Thank you

Example file-01.xlsm
ABCDEFGHI
1RowNational Code namelast nameUnion nameBoard codeBoard codeSide Election date
21181-842934-9SasanBahramiTools Unionfirst round1First Vice President1391/03/27
32181-842934-9SasanBahramiTools Union second period2Second Vice President1395/02/26
43181-842934-9SasanBahramiTools Union second period4Secretary1399/02/26
54181-987654-3AmirBahramiElectric Trade UnionFourth period6Inspector1400/02/30
Sheet1

Example file-01.xlsm
ABCDEFGHIJKLMN
1RowNational Codenamelast nameUnion nameSide of the first periodDate of the first periodSide of the second periodDate of the first periodSide of the ThirdperiodDate of the ThirdperiodSide of the Fourth periodDate of the Fourth periodNumber of company courses in the board of directors
21181-842934-9SasanBahramiTools UnionFirst Vice President1391/03/27Second Vice President1395/02/26Secretary1399/02/26003
32181-987654-3AmirBahramiElectric Trade Union000000Inspector1400/02/301
Sheet2
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Some considerations that I see in your example that you should review in your data.

Here it should be "Third" And you have blank spaces before texts.
1647873822215.png


It says "Date of the first period", it should say "Date of the second period"
It says "Thirdperiod", it should say "Third period"
1647874009678.png


Note: If the quality of your data is better, you will have better results.

Try this
VBA Code:
Sub reorganize()
  Dim sh1 As Worksheet, sh2 As Worksheet
  Dim i As Long, lr As Long, n As Long
  Dim f As Range, c As Range
  Dim prd As String
 
  Application.ScreenUpdating = False
  Set sh1 = Sheets("Sheet1")
  Set sh2 = Sheets("Sheet2")
  sh2.Rows("2:" & rows.count).ClearContents
 
  For i = 2 To sh1.Range("A" & Rows.Count).End(3).Row
    Set f = sh2.Range("B:B").Find(sh1.Range("B" & i).Value, , xlValues, xlWhole, , , False)
    If f Is Nothing Then
      n = n + 1
      lr = sh2.Range("A" & Rows.Count).End(3).Row + 1
      sh2.Range("A" & lr).Value = n
      sh2.Range("B" & lr).Resize(1, 4).Value = sh1.Range("B" & i).Resize(1, 4).Value
    Else
      lr = f.Row
    End If
    prd = WorksheetFunction.Trim(Split(WorksheetFunction.Trim(sh1.Range("F" & i).Value), " ")(0))
    Set c = sh2.Range("1:1").Find(prd, , xlValues, xlPart, , , False)
    If Not c Is Nothing Then
      sh2.Cells(lr, c.Column).Resize(1, 2).Value = sh1.Range("H" & i).Resize(1, 2).Value
    End If
    sh2.Range("N" & lr).Value = sh2.Range("N" & lr).Value + 1
  Next
  Application.ScreenUpdating = True
End Sub
 
Upvote 0

Using VBA to find duplicate or non-duplicate rows (common or non-common) in sheet 1 and move to sheet 2 in a row​

A table in sheet one contains the names of duplicate and non-duplicate persons who have participated in the union elections in consecutive or alternate terms for four years and all have different positions and positions. Courses and dates have participated in the elections and at the end, the number of participants in the elections should be added.
Example file-05.xlsm
ABCDEFGHI
1RowNational Code namelast nameUnion nameElection periodBoard position codeSide Election date
21181-842934-9SasanBahramiTools Unionfirst round1First Vice President1391/03/27
32181-842934-9SasanBahramiTools Unionsecond period2Second Vice President1395/02/26
43181-842934-9SasanBahramiTools Unionsecond period4Secretary1399/02/26
54181-987654-3AmirBahramiElectric Trade UnionFourth period6Inspector1400/02/30
6
Sheet1

Example file-05.xlsm
ABCDEFGHIJKLMN
1Personal profileThe first round of electionsThe second round of electionsThe third round of electionsThe fourth round of electionsNumber of periods of participation in elections
2RowNational CodeNameLast nameUnion nameSide Election DateElection DateSide Election DateElection DateSide Election DateElection DateSide of the Fourth periodDate of the Fourth period
31181-842934-9SasanBahramiTools UnionFirst Vice President1391/03/27Second Vice President1395/02/26Secretary1399/02/26003
42181-987654-3AmirBahramiElectric Trade Union000000Inspector1400/02/301
Sheet2
 
Upvote 0
Hello, good day, use the code you used for another topic that is similar and written, and complete the elections of each period (position and date) for the first, second, third and fourth elections, respectively. Thank you.
Sub remove_duplicates_leave_unique()
Dim a As Variant, b As Variant
Dim dic As Object
Dim i As Long, j As Long

Set dic = CreateObject("Scripting.Dictionary")
a = Sheets("Sheet1").Range("A2", Sheets("Sheet1").Range("i" & Rows.Count).End(3)).Value
ReDim b(1 To UBound(a, 1), 1 To 10)

For i = 1 To UBound(a)
If Not dic.exists(a(i, 9)) Then
j = dic.Count + 1
dic(a(i, 5)) = j
b(j, 1) = j
b(j, 2) = a(i, 2)
b(j, 3) = a(i, 3)
b(j, 4) = a(i, 4)
b(j, 5) = a(i, 5)
b(j, 6) = a(i, 6)
b(j, 7) = a(i, 7)
b(j, 8) = a(i, 8)
b(j, 9) = a(i, 9)
Else
j = dic(a(i, 5))
End If
b(j, 10) = b(j, 10) + 1
Next
Sheets("Sheet2").Range("A2").Resize(dic.Count, 10).Value = b
Sheet2.Columns().AutoFit
End Sub
 
Upvote 0
Hi, I used your codes, but the title and date of the election will not be transferred to sheet 2, and if it is transferred, the last title and date of the election will be transferred. Thank you for your help and support
 
Upvote 0
Some considerations that I see in your example that you should review in your data.

Here it should be "Third" And you have blank spaces before texts.
View attachment 60600

It says "Date of the first period", it should say "Date of the second period"
It says "Thirdperiod", it should say "Third period"
View attachment 60601

Note: If the quality of your data is better, you will have better results.

Try this
VBA Code:
Sub reorganize()
  Dim sh1 As Worksheet, sh2 As Worksheet
  Dim i As Long, lr As Long, n As Long
  Dim f As Range, c As Range
  Dim prd As String
 
  Application.ScreenUpdating = False
  Set sh1 = Sheets("Sheet1")
  Set sh2 = Sheets("Sheet2")
  sh2.Rows("2:" & rows.count).ClearContents
 
  For i = 2 To sh1.Range("A" & Rows.Count).End(3).Row
    Set f = sh2.Range("B:B").Find(sh1.Range("B" & i).Value, , xlValues, xlWhole, , , False)
    If f Is Nothing Then
      n = n + 1
      lr = sh2.Range("A" & Rows.Count).End(3).Row + 1
      sh2.Range("A" & lr).Value = n
      sh2.Range("B" & lr).Resize(1, 4).Value = sh1.Range("B" & i).Resize(1, 4).Value
    Else
      lr = f.Row
    End If
    prd = WorksheetFunction.Trim(Split(WorksheetFunction.Trim(sh1.Range("F" & i).Value), " ")(0))
    Set c = sh2.Range("1:1").Find(prd, , xlValues, xlPart, , , False)
    If Not c Is Nothing Then
      sh2.Cells(lr, c.Column).Resize(1, 2).Value = sh1.Range("H" & i).Resize(1, 2).Value
    End If
    sh2.Range("N" & lr).Value = sh2.Range("N" & lr).Value + 1
  Next
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hello, please check my message if possible. This is important to me.
 
Upvote 0

Forum statistics

Threads
1,223,920
Messages
6,175,376
Members
452,638
Latest member
Oluwabukunmi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top