Vladut
Vladut

Reputation: 657

How to compare two columns from different sheets and put a value in another sheet? vba

I have 3 worksheets: WUR, Homologation and read.

I want to read column 1 from "WUR", when i find first value i want to compare with first column from "Homologation", if the values is the same then put this values in firm column in worksheet 3, "Read". This code is from Button found in Worksheet 3.

I try this:

Sub Read_Click()

      Dim x As Integer
      Application.ScreenUpdating = False

      NumRows = ActiveWorkbook.Worksheets("WUR").Range("A1", ActiveWorkbook.Worksheets("Homologation").Range("A1").End(xlDown)).Rows.Count

      Range("A1").Select

      For x = 1 To NumRows

      Next

End Sub

With my code i try to find first values from the first column in "WUR" but my code work in Sheet 3, not in first WorkSheet where i want.

Upvotes: 0

Views: 197

Answers (1)

themaksmw
themaksmw

Reputation: 25

It might be because in

Range("A1").Select

you don't specify the worksheet where A1 has to be selected. If you therefore have currently another worksheet open, the selection will be made there. Try defining it like you did the line above

ActiveWorkbook.Worksheets("WUR").Range("A1").Select

Upvotes: -1

Related Questions