ERROR 1004 - how can i solve it?

GustavoR

New Member
Joined
Dec 8, 2014
Messages
37
Hi guys. I have been facing an error 1004 on my code to copy and paste a particular range everytime a specific cell is changed.
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo tratamento
' Application.ScreenUpdating = False
Dim KeyCells As Range
Set KeyCells = Worksheets("PAINEL").Range("B4")
Dim uf As String
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
uf = Application.WorksheetFunction.VLookup(Range("D4").Value, _
Worksheets("AUXILIAR").Range("B1:C27"), 2, 0)
Debug.Print uf
' Sheets(uf).Activate
Dim i
i = 1
Do While Worksheets(uf).Cells(7, i) <> Worksheets("PAINEL").Range("B4").Value
i = i + 1
Loop
Debug.Print i
Dim dadosaimportar As Range
dadosaimportar = ActiveWorkbook.Sheets(uf).Range(Cells(8, i), Cells(74, i + 11))
dadosaimportar.Copy
Worksheets("PAINEL").Activate
Range("C13").Select
Selection.PasteSpecial xlPasteAll
Application.CutCopyMode = False
Range("D4") = Application.WorksheetFunction.VLookup(uf, Worksheets("AUXILIAR").Range("A1:B27"), 2, 0)
End If
tratamento:
Debug.Print Err.Number
Application.ScreenUpdating = True
End Sub

all "uf" sheets are hidden, and it is important to stay this way. can you guys please gently help me?

ps.: this is the debug
PA (this is ok)​
75 (this is ok)​
1004
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try changing this line of code:
dadosaimportar = ActiveWorkbook...

to this:
set dadosaimportar = ActiveWorkbook...
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top