Can`t seem to get active cell row number into to my code

Eric Penfold

Active Member
Joined
Nov 19, 2021
Messages
431
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I have looked at websites ect but for some reason the code won`t pick up the active cell row number please help?
What is wrong with this part of code?
VBA Code:
Row = .ActiveCell.Row
Says Error "Method or Data Member not Found"


VBA Code:
Sub BOReason()

    Dim Ws             As Worksheet
    Dim LRow           As Long, Row As Range
    Dim x              As Variant, y As Variant, i As Variant
    Dim Rng            As Range, Comparerng As Range
    Dim YDat           As Date
    Dim TDat           As Date
    Dim StartTime      As Double
    Dim SecondsElapsed As Double
   
    StartTime = Timer
   
    With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
    End With

       

        Set Ws = ActiveSheet
        LRow = Ws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        
        YDat = Format(CDate(Application.WorksheetFunction.WorkDay(Date, -1)), "dd/mm/yyyy")
        TDat = CDate(Date)

        On Error Resume Next
        With Ws
            Set Rng = .Range("A2:A" & LRow).Find(YDat, LookIn:=xlValues, LookAt:=xlWhole)
            Row = .ActiveCell.Row

        With Rng
             If Rng Is Nothing Then
                .Range("A1").AutoFilter 1, Format(TDat, "dd/mm/yyyy")
            Else
                .Range("A1").AutoFilter 1, Format(TDat, "dd/mm/yyyy"), 2, Format(YDat, "dd/mm/yyyy")
             End If
             End With

          If Ws.Name <> "Summary" And Ws.Name <> "Trend" And Ws.Name <> "Supplier BO" And Ws.Name <> "Dif Depot" Then

            Set Comparerng = .Range("E2:E" & LRow)

                For Each x In Comparerng.SpecialCells(xlCellTypeVisible).Select
                For Each y In Comparerng.SpecialCells(xlCellTypeVisible).Select

                       If x = y Then
                             .Range("J" & y.ActiveCell.Row) = .Range("J" & x.ActiveCell.Row)
                        Else
                             Exit Sub
                        End If
                    Next y
               Next x
            End If

        .Range("AA1") = ""
        End With

    With Application
    .ScreenUpdating = True
    .Calculation = xlCalculationAutomatic
    End With


    Ws.ShowAllData

SecondsElapsed = Round(Timer - StartTime, 2)

MsgBox "This code ran successfully in " & SecondsElapsed & " seconds", vbInformation

End Sub
 
Eric, I dont get that error at all when row is dim as long, runs through nicely and returns row number
The only reason I can see for that happening is if you have another variable or sub with the same name
I haven`t got that.
Could I send my workbook to you to fix?
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
you can attach a sample workbook here using xl2bb. I can have a look at your data and combine with the code above
 
Upvote 0
Here you go thanks in advance

2022 Coventry Back OrderTest.xlsm
ABCDEFGHIJ
1Order DateCustomer NameOrder No.Ent ByCodeDescriptionBO Qty.Intact Stock LevelsNotesBackOrderReasonCode
201/07/2022Entex Projects Ltd SO0064241NIJJMF104 STAKKAbox Quad Access Chamber 915x445x150mm BT Approved 10IS
301/07/2022J&A Groundworks Ltd SO0064263NG 6VCR350 600mm Vision 600 Chamber Restrictor Cap 350mm Opening 10SD
401/07/2022JD Excavations Tyrone Ltd SO0064277NIJ6VCR350 600mm Vision 600 Chamber Restrictor Cap 350mm Opening 60SD
501/07/2022J&A Groundworks Ltd SO0064263NG 6VCA672 160mm Vision 600 chamber, outlet adaptor to 160mm UPVC – Socket 1047LS
601/07/2022JD Excavations Tyrone Ltd SO0064277NIJ6VCA12225315mm Vision 600 chamber, outlet adaptor to 225mm TW – Socket (Level Invert) 10NSI
701/07/2022Flint Property Group Ltd SO0064218LK 4VCF280S 280mm PVCu Cover & Frame Square 30LS
801/07/2022Flint Property Group Ltd SO0064218LK 450VCFC Polypropylene Cover & Frame: 450mm dia 50 kn Circular Locked 20ONI
901/07/2022J Holland Construction LtdSO0064286NIJ150TW90 150mm ID/ 178mm OD Twinwall Duct Bend 90deg Long Radius; P/E 70ONI
1001/07/2022JD Excavations Tyrone Ltd SO0064277NIJ106VR 250mm Spigot to 160mm Socket Reducer Level Invert 60LS
1104/07/2022RM Contractors Ltd SO0064328NIJVJ4 Viking Johnson Maxi Fit 107-132mm Coupler Straight Coupler 20LS
1204/07/2022JD Excavations Tyrone Ltd SO0064387NIJSTOP300R300mm Expanding Pipe Stopper 1" Test Thread Pressed Steel; 297-310mm range 30LS
1304/07/2022Stave-Con Ltd SO0064394NIJ450VCFS Polypropylene Cover & Frame: 450 x 450mm 50 kn Square to Round 200LS
1404/07/2022Stave-Con Ltd SO0064394NIJ450VC4 450mm Inspection Chamber Base 110mm Inlet for installation up to 1.2m 20ONI
1504/07/2022Barnwood Limited SO0064408NG 19004AcoThreshold Channel End Plate 20mm long x 100mm deep x 61mm wide 40ONI
1604/07/2022Hewlett & Sons Groundworks LtdSO0064375NIJ160TWBL 160mm OD TW Electrical Duct x50m Coil Black (140mm ID) 23ONI
1705/07/2022O'Hagan Civils Ltd SO0064478LK DUCT60 Naylor 600x600mm Duct Access Box 335mm Depth B125 Loading 540ONI
1805/07/2022Harkmac Construction Ltd SO0064472NIJ4VPR 110mm Underground Drainage Rocker Pipe x600mm 420SO
1905/07/2022Harkmac Construction Ltd SO0064472NIJ450VCFCPolypropylene Cover & Frame: 450mm dia 50 kn Circular Locked 200ONI
2005/07/2022Harkmac Construction Ltd SO0064472NIJ450VCFCPolypropylene Cover & Frame: 450mm dia 50 kn Circular Locked 30ONI
2106/07/2022Crossville Developments LtdSO0064516LK 63PROEC63mm Barrier Pipe End Plug; Type A (Fits both Protecta-Line & Puriton) 10NSI
2206/07/2022L4 Civil Engineering LimitedSO0064552NIJVFFAC19226" Clay/110mm Plastic, 170-192mm - 110-122mm Flexible Adaptor Coupling 70SO
2307/07/2022O'Hagan Civils Ltd SO0064761LK DUCT60 Naylor 600x600mm Duct Access Box 335mm Depth B125 Loading 729SL
2407/07/2022Leidon Limited SO0064698NIJ6VF20D 160mm PVC Drainage D/Socket Coupler 300ONI
2507/07/2022Opel Construction LtdSO0064727NG 6VCR350600mm Vision 600 Chamber Restrictor Cap 350mm Opening 51SO
2611/07/2022Galamast Ltd SO0064907NGPIPE35 35mm Pipe Insulation 13mm Wall Thickness x2m 11117IS
2711/07/2022Connop & Son Ltd SO0064846LK6VF90D 160mm UPVC Drainage D/Socket Bend 87.5deg 20ONI
2811/07/2022Leidon Limited SO0064826NG6VF20D 160mm PVC Drainage D/Socket Coupler 526NSI
2911/07/2022Newtownstewart Construction UK LtdSO0065000NG31.6539Frost PVC Spigot Adaptor BSP6 to160mm plastic (extends 150mm long.) 6-1FR
3011/07/2022JD Excavations Tyrone Ltd SO0064917NG225R160225mm Naylor TW Socket to 160mm UPVC Socket Level Invert Reducer 10SO
3112/07/2022Leidon Limited SO0064826NG10VF20D250mm Underground Drainage D/Socket Coupler 20LS
3212/07/2022Goldmax Ltd SO0064801LK UWTSL150Underground Warning Tape - Street Lighting Cable (x365m) - Yellow 20ONI
3312/07/2022Foran Construction Ltd SO0065127NIJSTOP1P Inflatable Pipe Stopper Hand Pump - Schrader Valve 11LS
3412/07/2022Umberslade Business Services LtdSO0065096SB 96BTT 96mm Telecoms Duct Equal Swept 90deg Jct Grey (BT Type) 40ONI
3512/07/2022Richard Hall Ltd SO0065088NIJ6VF90D 160mm UPVC Drainage D/Socket Bend 87.5deg 20NSI
3612/07/2022Entex Projects Ltd SO0065044LK 6VF90D 160mm PVC Drainage D/Socket Coupler 40
Jul
 
Upvote 0
Hi,
I ran your workbook with the code you supplied at top of page. the only change I made to your code was to remove the full stop before activecell and to dim row as long.
The code ran fine and gave me a time of 0.26 seconds. So the error must be within your workbook.

As you said earlier that removing the full stop after activecell gave you "Expected Function or Variable" then I can only assume that you have a sub or function with the same name somewhere along the line.

Some things you could try are to use 'MyRow' instead of row
VBA Code:
MyRow = ActiveCell.Row
and
VBA Code:
dim Myrow as long

or copy the data you have pasted above into a fresh workbook and paste your origional code (taking the full stop out and dim row as long) and see if that works
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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