VBA Clueless
New Member
- Joined
- Mar 11, 2015
- Messages
- 4
I am attempting to create a vba script for excel to do the following task from a two column list of data (subnets and serial numbers) but am a COMPLETE VBA know-nothing.
• Check the 1st column (subnets) on ‘Sheet1’ for a unique value AND does not contain an “x” in its corresponding cell in column 3 (marker)
• Copy the value from the adjacent cell\column2 (Serial numbers) (on ‘Sheet1) and write to the first column on another worksheet (‘Sheet2’)
• Write a value in Column 3 as an identifier that its data has been copied over to the other sheet. This will allow me to pass through the list multiple times and ignore anything that has already been copied
• Loop/repeat through the list as many times as needed until reaching a specific number of results on Sheet2
Initial Spreadsheet
[table="width: 500, class: grid"]
[tr]
[td][/td]
[td]Column A[/td]
[td]Column B[/td]
[td]Column C[/td]
[/tr]
[tr]
[td]Row 1[/td]
[td]Subnet-A[/td]
[td]Serial-001[/td]
[td][/td]
[/tr]
[tr]
[td]Row 2[/td]
[td]Subnet-A[/td]
[td]Serial-002[/td]
[td][/td]
[/tr]
[tr]
[td]Row 3[/td]
[td]Subnet-A[/td]
[td]Serial-003[/td]
[td][/td]
[/tr]
[tr]
[td]Row 4[/td]
[td]Subnet-B[/td]
[td]Serial-004[/td]
[td][/td]
[/tr]
[tr]
[td]Row 5[/td]
[td]Subnet-B[/td]
[td]Serial-005[/td]
[td][/td]
[/tr]
[tr]
[td]Row 6[/td]
[td]Subnet-B[/td]
[td]Serial-006[/td]
[td][/td]
[/tr]
[tr]
[td]Row 7[/td]
[td]Subnet-C[/td]
[td]Serial-007[/td]
[td][/td]
[/tr]
[tr]
[td]Row 8[/td]
[td]Subnet-C[/td]
[td]Serial-008[/td]
[td][/td]
[/tr]
[tr]
[td]Row 9[/td]
[td]Subnet-D[/td]
[td]Serial-009[/td]
[td][/td]
[/tr]
[tr]
[td]Row 10[/td]
[td]Subnet-E[/td]
[td]Serial-010[/td]
[td][/td]
[/tr]
[tr]
[td]Row 11[/td]
[td]Subnet-E[/td]
[td]Serial-011[/td]
[td][/td]
[/tr]
[tr]
[td]Row 12[/td]
[td]Subnet-E[/td]
[td]Serial-012[/td]
[td][/td]
[/tr]
[tr]
[td]Row 13[/td]
[td]Subnet-F[/td]
[td]Serial-013[/td]
[td][/td]
[/tr]
[tr]
[td]Row 14[/td]
[td]Subnet-F[/td]
[td]Serial-014[/td]
[td][/td]
[/tr]
[tr]
[td]Row 15[/td]
[td]Subnet-F[/td]
[td]Serial-015[/td]
[td][/td]
[/tr]
[/table]
Workflow\My Logic - flawed as it may be
[table="width: 1100, class: grid"]
[tr]
[td] Start VBA script [/td]
[td][/td]
[td]Column A[/td]
[td]Column B[/td]
[td](action1)[/td]
[td]Column C[/td]
[td] (action2)[/td]
[/tr]
[tr]
[td] Finds unique value "Subnet-A" in column A, finds no "x" in Column C, continues with actions [/td]
[td]Row 1[/td]
[td]Subnet-A[/td]
[td]Serial-001[/td]
[td] Writes an "X" in Column C -----> [/td]
[td] x [/td]
[td] Copies serial number value from Column B to Column A on Sheet2 [/td]
[/tr]
[tr]
[td] Subnet-A is no longer unique - moves to next row [/td]
[td]Row 2[/td]
[td]Subnet-A[/td]
[td]Serial-002[/td]
[td] [/td]
[td] [/td]
[td] [/td]
[/tr]
[tr]
[td] Subnet-A is no longer unique - moves to next row [/td]
[td]Row 3[/td]
[td]Subnet-A[/td]
[td]Serial-003[/td]
[td] [/td]
[td] [/td]
[td] [/td]
[/tr]
[tr]
[td] Finds unique value "Subnet-B" in column A, finds no "x" in Column C, continues with actions [/td]
[td]Row 4[/td]
[td]Subnet-B[/td]
[td]Serial-004[/td]
[td] Writes an "X" in Column C -----> [/td]
[td]x [/td]
[td] Copies serial number value from Column B to Column A on Sheet2 [/td]
[/tr]
[tr]
[td] Subnet-B is no longer unique - moves to next row [/td]
[td]Row 5[/td]
[td]Subnet-B[/td]
[td]Serial-005[/td]
[td] [/td]
[td] [/td]
[td] [/td]
[/tr]
[tr]
[td] Subnet-B is no longer unique - moves to next row [/td]
[td]Row 6[/td]
[td]Subnet-B[/td]
[td]Serial-006[/td]
[td] [/td]
[td] [/td]
[td] [/td]
[/tr]
[tr]
[td] Finds unique value "Subnet-C" in column A, finds no "x" in Column C, continues with actions [/td]
[td]Row 7[/td]
[td]Subnet-C[/td]
[td]Serial-007[/td]
[td] Writes an "X" in Column C -----> [/td]
[td]x [/td]
[td] Copies serial number value from Column B to Column A on Sheet2 [/td]
[/tr]
[tr]
[td] Subnet-C is no longer unique - moves to next row [/td]
[td]Row 8[/td]
[td]Subnet-C[/td]
[td]Serial-008[/td]
[td] [/td]
[td] [/td]
[td] [/td]
[/tr]
[tr]
[td] Finds unique value "Subnet-D" in column A, finds no "x" in Column C, continues with actions [/td]
[td]Row 9[/td]
[td]Subnet-D[/td]
[td]Serial-009[/td]
[td] Writes an "X" in Column C -----> [/td]
[td]x [/td]
[td] Copies serial number value from Column B to Column A on Sheet2 [/td]
[/tr]
[tr]
[td] Finds unique value "Subnet-E" in column A, finds no "x" in Column C, continues with actions [/td]
[td]Row 10[/td]
[td]Subnet-E[/td]
[td]Serial-010[/td]
[td] Writes an "X" in Column C -----> [/td]
[td]x [/td]
[td] Copies serial number value from Column B to Column A on Sheet2 [/td]
[/tr]
[tr]
[td] Subnet-E is no longer unique - moves to next row [/td]
[td]Row 11[/td]
[td]Subnet-E[/td]
[td]Serial-011[/td]
[td] [/td]
[td] [/td]
[td] [/td]
[/tr]
[tr]
[td] Subnet-E is no longer unique - moves to next row [/td]
[td]Row 12[/td]
[td]Subnet-E[/td]
[td]Serial-012[/td]
[td] [/td]
[td] [/td]
[td] [/td]
[/tr]
[tr]
[td] Finds unique value "Subnet-F" in column A, finds no "x" in Column C, continues with actions [/td]
[td]Row 13[/td]
[td]Subnet-F[/td]
[td]Serial-013[/td]
[td] Writes an "X" in Column C -----> [/td]
[td]x [/td]
[td] Copies serial number value from Column B to Column A on Sheet2 [/td]
[/tr]
[tr]
[td] Subnet-F is no longer unique - moves to next row [/td]
[td]Row 14[/td]
[td]Subnet-F[/td]
[td]Serial-014[/td]
[td] [/td]
[td] [/td]
[td] [/td]
[/tr]
[tr]
[td] Subnet-F is no longer unique - moves to next row [/td]
[td]Row 15[/td]
[td]Subnet-F[/td]
[td]Serial-015[/td]
[td] [/td]
[td] [/td]
[td] [/td]
[/tr]
[/table]
Desired results on ‘Sheet2’ based on above logic
[table="width: 200, class: grid"]
[tr]
[td]Sheet2 - Column A[/td]
[/tr]
[tr]
[td]Serial-001[/td]
[/tr]
[tr]
[td]Serial-004[/td]
[/tr]
[tr]
[td]Serial-007[/td]
[/tr]
[tr]
[td]Serial-009[/td]
[/tr]
[tr]
[td]Serial-010[/td]
[/tr]
[tr]
[td]Serial-013[/td]
[/tr]
[/table]
The VBA code I have so far only parses Column A and copies the unique data to sheet2 (it’s a start right). The code I have is as follows:
Public Sub MyTest()
Sheet1.Range("A:A").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheet2.Range("A1"), Unique:=True
End Sub
Any help that can be provided would be greatly appreciated.
Warm Regards,
VBA Clueless
• Check the 1st column (subnets) on ‘Sheet1’ for a unique value AND does not contain an “x” in its corresponding cell in column 3 (marker)
• Copy the value from the adjacent cell\column2 (Serial numbers) (on ‘Sheet1) and write to the first column on another worksheet (‘Sheet2’)
• Write a value in Column 3 as an identifier that its data has been copied over to the other sheet. This will allow me to pass through the list multiple times and ignore anything that has already been copied
• Loop/repeat through the list as many times as needed until reaching a specific number of results on Sheet2
Initial Spreadsheet
[table="width: 500, class: grid"]
[tr]
[td][/td]
[td]Column A[/td]
[td]Column B[/td]
[td]Column C[/td]
[/tr]
[tr]
[td]Row 1[/td]
[td]Subnet-A[/td]
[td]Serial-001[/td]
[td][/td]
[/tr]
[tr]
[td]Row 2[/td]
[td]Subnet-A[/td]
[td]Serial-002[/td]
[td][/td]
[/tr]
[tr]
[td]Row 3[/td]
[td]Subnet-A[/td]
[td]Serial-003[/td]
[td][/td]
[/tr]
[tr]
[td]Row 4[/td]
[td]Subnet-B[/td]
[td]Serial-004[/td]
[td][/td]
[/tr]
[tr]
[td]Row 5[/td]
[td]Subnet-B[/td]
[td]Serial-005[/td]
[td][/td]
[/tr]
[tr]
[td]Row 6[/td]
[td]Subnet-B[/td]
[td]Serial-006[/td]
[td][/td]
[/tr]
[tr]
[td]Row 7[/td]
[td]Subnet-C[/td]
[td]Serial-007[/td]
[td][/td]
[/tr]
[tr]
[td]Row 8[/td]
[td]Subnet-C[/td]
[td]Serial-008[/td]
[td][/td]
[/tr]
[tr]
[td]Row 9[/td]
[td]Subnet-D[/td]
[td]Serial-009[/td]
[td][/td]
[/tr]
[tr]
[td]Row 10[/td]
[td]Subnet-E[/td]
[td]Serial-010[/td]
[td][/td]
[/tr]
[tr]
[td]Row 11[/td]
[td]Subnet-E[/td]
[td]Serial-011[/td]
[td][/td]
[/tr]
[tr]
[td]Row 12[/td]
[td]Subnet-E[/td]
[td]Serial-012[/td]
[td][/td]
[/tr]
[tr]
[td]Row 13[/td]
[td]Subnet-F[/td]
[td]Serial-013[/td]
[td][/td]
[/tr]
[tr]
[td]Row 14[/td]
[td]Subnet-F[/td]
[td]Serial-014[/td]
[td][/td]
[/tr]
[tr]
[td]Row 15[/td]
[td]Subnet-F[/td]
[td]Serial-015[/td]
[td][/td]
[/tr]
[/table]
Workflow\My Logic - flawed as it may be
[table="width: 1100, class: grid"]
[tr]
[td] Start VBA script [/td]
[td][/td]
[td]Column A[/td]
[td]Column B[/td]
[td](action1)[/td]
[td]Column C[/td]
[td] (action2)[/td]
[/tr]
[tr]
[td] Finds unique value "Subnet-A" in column A, finds no "x" in Column C, continues with actions [/td]
[td]Row 1[/td]
[td]Subnet-A[/td]
[td]Serial-001[/td]
[td] Writes an "X" in Column C -----> [/td]
[td] x [/td]
[td] Copies serial number value from Column B to Column A on Sheet2 [/td]
[/tr]
[tr]
[td] Subnet-A is no longer unique - moves to next row [/td]
[td]Row 2[/td]
[td]Subnet-A[/td]
[td]Serial-002[/td]
[td] [/td]
[td] [/td]
[td] [/td]
[/tr]
[tr]
[td] Subnet-A is no longer unique - moves to next row [/td]
[td]Row 3[/td]
[td]Subnet-A[/td]
[td]Serial-003[/td]
[td] [/td]
[td] [/td]
[td] [/td]
[/tr]
[tr]
[td] Finds unique value "Subnet-B" in column A, finds no "x" in Column C, continues with actions [/td]
[td]Row 4[/td]
[td]Subnet-B[/td]
[td]Serial-004[/td]
[td] Writes an "X" in Column C -----> [/td]
[td]x [/td]
[td] Copies serial number value from Column B to Column A on Sheet2 [/td]
[/tr]
[tr]
[td] Subnet-B is no longer unique - moves to next row [/td]
[td]Row 5[/td]
[td]Subnet-B[/td]
[td]Serial-005[/td]
[td] [/td]
[td] [/td]
[td] [/td]
[/tr]
[tr]
[td] Subnet-B is no longer unique - moves to next row [/td]
[td]Row 6[/td]
[td]Subnet-B[/td]
[td]Serial-006[/td]
[td] [/td]
[td] [/td]
[td] [/td]
[/tr]
[tr]
[td] Finds unique value "Subnet-C" in column A, finds no "x" in Column C, continues with actions [/td]
[td]Row 7[/td]
[td]Subnet-C[/td]
[td]Serial-007[/td]
[td] Writes an "X" in Column C -----> [/td]
[td]x [/td]
[td] Copies serial number value from Column B to Column A on Sheet2 [/td]
[/tr]
[tr]
[td] Subnet-C is no longer unique - moves to next row [/td]
[td]Row 8[/td]
[td]Subnet-C[/td]
[td]Serial-008[/td]
[td] [/td]
[td] [/td]
[td] [/td]
[/tr]
[tr]
[td] Finds unique value "Subnet-D" in column A, finds no "x" in Column C, continues with actions [/td]
[td]Row 9[/td]
[td]Subnet-D[/td]
[td]Serial-009[/td]
[td] Writes an "X" in Column C -----> [/td]
[td]x [/td]
[td] Copies serial number value from Column B to Column A on Sheet2 [/td]
[/tr]
[tr]
[td] Finds unique value "Subnet-E" in column A, finds no "x" in Column C, continues with actions [/td]
[td]Row 10[/td]
[td]Subnet-E[/td]
[td]Serial-010[/td]
[td] Writes an "X" in Column C -----> [/td]
[td]x [/td]
[td] Copies serial number value from Column B to Column A on Sheet2 [/td]
[/tr]
[tr]
[td] Subnet-E is no longer unique - moves to next row [/td]
[td]Row 11[/td]
[td]Subnet-E[/td]
[td]Serial-011[/td]
[td] [/td]
[td] [/td]
[td] [/td]
[/tr]
[tr]
[td] Subnet-E is no longer unique - moves to next row [/td]
[td]Row 12[/td]
[td]Subnet-E[/td]
[td]Serial-012[/td]
[td] [/td]
[td] [/td]
[td] [/td]
[/tr]
[tr]
[td] Finds unique value "Subnet-F" in column A, finds no "x" in Column C, continues with actions [/td]
[td]Row 13[/td]
[td]Subnet-F[/td]
[td]Serial-013[/td]
[td] Writes an "X" in Column C -----> [/td]
[td]x [/td]
[td] Copies serial number value from Column B to Column A on Sheet2 [/td]
[/tr]
[tr]
[td] Subnet-F is no longer unique - moves to next row [/td]
[td]Row 14[/td]
[td]Subnet-F[/td]
[td]Serial-014[/td]
[td] [/td]
[td] [/td]
[td] [/td]
[/tr]
[tr]
[td] Subnet-F is no longer unique - moves to next row [/td]
[td]Row 15[/td]
[td]Subnet-F[/td]
[td]Serial-015[/td]
[td] [/td]
[td] [/td]
[td] [/td]
[/tr]
[/table]
Desired results on ‘Sheet2’ based on above logic
[table="width: 200, class: grid"]
[tr]
[td]Sheet2 - Column A[/td]
[/tr]
[tr]
[td]Serial-001[/td]
[/tr]
[tr]
[td]Serial-004[/td]
[/tr]
[tr]
[td]Serial-007[/td]
[/tr]
[tr]
[td]Serial-009[/td]
[/tr]
[tr]
[td]Serial-010[/td]
[/tr]
[tr]
[td]Serial-013[/td]
[/tr]
[/table]
The VBA code I have so far only parses Column A and copies the unique data to sheet2 (it’s a start right). The code I have is as follows:
Public Sub MyTest()
Sheet1.Range("A:A").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheet2.Range("A1"), Unique:=True
End Sub
Any help that can be provided would be greatly appreciated.
Warm Regards,
VBA Clueless