Sub or Function not defined error???

perezpa

New Member
Joined
Jun 17, 2011
Messages
17
Let's play Where's Waldo! Except that in this case, Waldo is the line that is giving me an error! I can't find it! Can you?

Code:
Option Explicit

Sub La_Joa()


Dim Centro As Range
Dim resumen As Worksheet
Dim Agregado As Worksheet
Dim rngCell As Range
Dim i As Integer

'Range("A1:F55").AdvancedFilter Action:=xlFilterInPlace, Unique:=True

'Columns("G:G").Delete Shift:=xlToLeft
'Columns("K:P").Delete Shift:=xlToLeft

Set resumen = Worksheets("Resumen")
Set Agregado = Worksheets("Agregado")
    
For Each rngCell In Range("Center")

    For i = 1 To 50
        If Cell(i, 3).Value2 = "600" Then
            Cell(i, 3).Select
            Range(Selection, Selection.End(xlToRight)).Select
            Range(Selection, Selection.End(xlUp)).Copy
        End If
    Next
    Agregado.Range("tbPro[PosID]").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

Next rngCell


End Sub

Compile Error: Sub or Function not defined.


Thank you in advance!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
at a guess , change
If Cells(i, 3).Value2 = "600" Then
to
If Cells(i, 3).Value2 = 600 Then
 
Upvote 0
is Range("Center") perhaps smaller than 50 rows? You hardcode 50 rows in the loop, but maybe your named range is smaller...

And I wonder why you use Value2. What is the benefit of that? I have never used it myself, nor have I ever seen it used... I always use just plain Value. Does it work if you switch those around?
 
Upvote 0
When the error occurs, choose to Debug, go to then in the immediate pane (Ctrl + G)
and type:
?typename(selection.value)
then Enter,
then
?typename(selection.value2)
then Enter.
What results do you get?
Also, is what's selected (just one cell) what you expect to be selected at this point.

The code is strange, because you iterate through each cell in a range using rngCell, but you never use it within the loop. Inside this loop you copy varying ranges to the clipboard, but you dont paste any but the last range (when i = 50). Is this what you intend?
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,750
Members
452,940
Latest member
rootytrip

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