Wasserkopf
New Member
- Joined
- Feb 1, 2018
- Messages
- 6
Hello all. I'm a newbie, but I have found this website to be the most informative in my quest to learn VBA. Most of the issues I've come across I have been able to solve, but now I'm stumped.
I have a workbook which contains two worksheets, both containing a column (A) with numbers) and a second column B with another set or numbers. "Sheet1" is a master list and "Sheet2" the second sheet is a list of changes that need to be made to the first. I am trying to find a vba code that finds anything in Sheet1/Column A with those in sheet2/column A. If the cells match, change the value of sheet1/column B to what is listed in sheet2/columnB
Example
Sheet1
[TABLE="width: 25"]
<tbody>[TR]
[TD]12345[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]67890[/TD]
[TD]11[/TD]
[/TR]
[TR]
[TD]23456[/TD]
[TD]20[/TD]
[/TR]
[TR]
[TD]78901[/TD]
[TD]21[/TD]
[/TR]
[TR]
[TD]34567[/TD]
[TD]32[/TD]
[/TR]
</tbody>[/TABLE]
Sheet2
[TABLE="class: outer_border, width: 25, align: left"]
<tbody>[TR]
[TD]23456[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]34567[/TD]
[TD]10[/TD]
[/TR]
</tbody>[/TABLE]
After the code is run, Sheet1 should look like:
[TABLE="class: outer_border, width: 26"]
<tbody>[TR]
[TD]12345[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]67890[/TD]
[TD]11[/TD]
[/TR]
[TR]
[TD]23456[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]78901[/TD]
[TD]21[/TD]
[/TR]
[TR]
[TD]34567[/TD]
[TD]10[/TD]
[/TR]
</tbody>[/TABLE]
I found the following code to delete cells listed in sheet2, but could not make it work to change the values in sheet1.
In my scenario, the master list has over 1500 entries, so this is a good candidate for a VBA macro. Any help would be greatly appreciated!
Wasserkopf
I have a workbook which contains two worksheets, both containing a column (A) with numbers) and a second column B with another set or numbers. "Sheet1" is a master list and "Sheet2" the second sheet is a list of changes that need to be made to the first. I am trying to find a vba code that finds anything in Sheet1/Column A with those in sheet2/column A. If the cells match, change the value of sheet1/column B to what is listed in sheet2/columnB
Example
Sheet1
[TABLE="width: 25"]
<tbody>[TR]
[TD]12345[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]67890[/TD]
[TD]11[/TD]
[/TR]
[TR]
[TD]23456[/TD]
[TD]20[/TD]
[/TR]
[TR]
[TD]78901[/TD]
[TD]21[/TD]
[/TR]
[TR]
[TD]34567[/TD]
[TD]32[/TD]
[/TR]
</tbody>[/TABLE]
Sheet2
[TABLE="class: outer_border, width: 25, align: left"]
<tbody>[TR]
[TD]23456[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]34567[/TD]
[TD]10[/TD]
[/TR]
</tbody>[/TABLE]
After the code is run, Sheet1 should look like:
[TABLE="class: outer_border, width: 26"]
<tbody>[TR]
[TD]12345[/TD]
[TD]10[/TD]
[/TR]
[TR]
[TD]67890[/TD]
[TD]11[/TD]
[/TR]
[TR]
[TD]23456[/TD]
[TD]15[/TD]
[/TR]
[TR]
[TD]78901[/TD]
[TD]21[/TD]
[/TR]
[TR]
[TD]34567[/TD]
[TD]10[/TD]
[/TR]
</tbody>[/TABLE]
I found the following code to delete cells listed in sheet2, but could not make it work to change the values in sheet1.
Code:
Private Sub DeleteFromList()
Dim Row As Long
Dim FoundAgent As Range
Dim LastCell As Long
Dim a As Variant
Dim x As Variant
Sheets("Delete").Activate
LastCell = Sheets("Delete").Cells(Rows.Count, 1).End(xlUp).Row
For x = 1 To LastCell
a = Sheets("Delete").Cells(x, 1).Value
a = Left(Trim(a), 7)
Sheets("Delete").Cells(x, 2).Value = a
EmptyCell = EmptyCell + 1
Next x
Worksheets("Delete").Columns(1).EntireColumn.Delete
For Row = Range("A65536").End(xlUp).Row To 2 Step -1
Set FoundAgent = Sheets("Agent_IDs_with_AUTH_Codes").Range("A:A").Find(Cells(Row, 1), LookIn:=xlValues, lookat:=xlPart)
If Not FoundAgent Is Nothing Then
Cells(Row, 1).EntireRow.Delete
End If
Next Row
End Sub
In my scenario, the master list has over 1500 entries, so this is a good candidate for a VBA macro. Any help would be greatly appreciated!
Wasserkopf