I have been struggling with this one for a while with no success. I wrote a code to import some data from a database, with the added problem they have different formats. So I wrote a section which would go through the other base and bring data back on the right order (that is not the entire code. I have done all the proper set statements for the objects):
Dim wb_atual, wb_verificar As Workbook
Dim sheet_atual, sheet_verificar As Worksheet
Dim choice, lin_max, lin_b_max, col, col_id, col_max, i, j, k As Integer
Dim is_equal As Boolean
For i = 1 To col_max
col = wb_verificar.Sheets(sheet_verificar.Name).Range("1:1").Find(wb_atual.Sheets(sheet_atual.Name).Cells(2, i).Value, LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns, searchdirection:=xlNext).Column
sheet_atual.Cells(j, i).Value = sheet_verificar.Range(sheet_verificar.Cells(j - 1, col), sheet_verificar.Cells(j - 1, col)).Value
lin_b_max = lin_b_max + 1
Next i
That is the block that caused the error, specifically the "col" variable line. What that line does is to look for a column header from a worksheet in another one, and stores the number of the column. That loop works fine for i=1 and 2, but at the third iteration I get the error.
setkeyword, somewhere in the code unseen, or yourFindstatement is not finding what you have asked of it. - Rusan Kax