Sheets("Dados").Range("A" & Sheets("Pesquisa").Range("W" & ListBox1.ListIndex + 2)).Select
That's a lot of things going on in a single statement, with several reasons for things to go awry.
Break it down.
First get your Worksheet
objects:
Dim dadosSheet As Worksheet
Set dadosSheet = ActiveWorkbook.Worksheets("Dados") 'possible error 9 here
Dim pesquisaSheet As Worksheet
Set pesquisaSheet = ActiveWorkbook.Worksheets("Pesquisa") 'possible error 9 here
Next we want to build a Range
address string in column W
, from ListBox1.ListIndex
, and get a rowIndex
from that cell in the pesquisaSheet
:
Dim rowSourceAddress As String
rowSourceAddress = "W" & ListBox1.ListIndex + 2 ' definitely a positive integer
Dim rowIndex As Long
rowIndex = pesquisaSheet.Range(rowSourceAddress).Value ' possible error 13 here
Debug.Assert rowIndex > 0 ' suspect this assertion will fail
Then we want to build another Range
address string in column A
:
Dim targetAddress As String
targetAddress = "A" & rowIndex ' if rowIndex isn't a positive integer...
Dim targetRange As Range
Set targetRange = dadosSheet.Range(targetAddress) '...error 1004 is thrown here
And lastly we want to Select
that range:
targetRange.Select
Sure, it's more code - and arguably a bit more local variables than needed. But with everything explicit and every member call in its own instruction, any given instruction has only 1 reason to fail, which makes debugging much easier.