GovindRajan
New Member
- Joined
- Nov 11, 2019
- Messages
- 3
hi i have a written a macro to search and find set of variables from one sheet( here give as reportsheet) with another (datasheet) and copy value next to it.
search works fine if all the search items are in datasheet but if something is not available i want reportsheet cell(k,5)to have value "need manual verification" i have tried many ways but since i am new to excel vba everything goes wrong
my code without option for search result is as follows. it would be great if someone could help me in modifying this. Thanks
Option Explicit
Sub search_and_find()
Dim datasheet As Worksheet
Dim reportsheet As Worksheet
Dim variablename As String
Dim finalrow As Integer
Dim i As Integer
Dim j As String
Dim k As Integer
Dim finalrsheet As Integer
Set datasheet = Sheet1
Set reportsheet = Sheet2
reportsheet.Select
Range("a1").Select
With ActiveSheet
finalrsheet = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
For i = 2 To finalrsheet
Cells(i, 1).Select
Selection.Copy
Sheet3.Activate
Range("a1").PasteSpecial
variablename = Range("a1")
datasheet.Activate
j = Range("h1:q3000").Find(What:=variablename).Select
Selection.Offset(0, 5).Copy
reportsheet.Activate
Cells(i, 4).PasteSpecial
Next i
reportsheet.Activate
For k = 2 To finalrsheet
If Cells(k, 2).Value = Cells(k, 4).Value Then
Cells(k, 5).Value = "No change"
Else
Cells(k, 5).Value = "Change"
End If
Next k
End Sub
search works fine if all the search items are in datasheet but if something is not available i want reportsheet cell(k,5)to have value "need manual verification" i have tried many ways but since i am new to excel vba everything goes wrong
my code without option for search result is as follows. it would be great if someone could help me in modifying this. Thanks
Option Explicit
Sub search_and_find()
Dim datasheet As Worksheet
Dim reportsheet As Worksheet
Dim variablename As String
Dim finalrow As Integer
Dim i As Integer
Dim j As String
Dim k As Integer
Dim finalrsheet As Integer
Set datasheet = Sheet1
Set reportsheet = Sheet2
reportsheet.Select
Range("a1").Select
With ActiveSheet
finalrsheet = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
For i = 2 To finalrsheet
Cells(i, 1).Select
Selection.Copy
Sheet3.Activate
Range("a1").PasteSpecial
variablename = Range("a1")
datasheet.Activate
j = Range("h1:q3000").Find(What:=variablename).Select
Selection.Offset(0, 5).Copy
reportsheet.Activate
Cells(i, 4).PasteSpecial
Next i
reportsheet.Activate
For k = 2 To finalrsheet
If Cells(k, 2).Value = Cells(k, 4).Value Then
Cells(k, 5).Value = "No change"
Else
Cells(k, 5).Value = "Change"
End If
Next k
End Sub