Code not running to last row

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,338
Office Version
  1. 365
Platform
  1. Windows
I have code that is supposed to perform all the way to the last row that has data in column H

But it seems to stops right before the last two rows. So if I have all the way to row 739, its not putting data in 738 or 739 column 13

If I add data to H740 and H741 I get data in column M (13) for 738 and 739.

Help Please. I need it to go to the last row of data

Code:
ActiveSheet.AutoFilterMode = False
Application.Calculation = xlManual

Sheet11.Activate

Dim ws As Worksheet
Dim st1 As String, st2 As String
Dim a As Long
Dim cont As Long

  Set ws = ActiveSheet

  cont = Application.WorksheetFunction.CountA(ws.Range("h:h"))

  For a = 4 To cont
  
    If ws.Cells(a, 5) = 0 And ws.Cells(a, 7) = 0 Then
      ws.Cells(a, 12).Value = 1
      ws.Cells(a, 13).Value = 1
      
    End If
        
    If ws.Cells(a, 6) <> "" Then
      st1 = ws.Cells(a, 6)
      For B = a - 1 To 1 Step -1
        st2 = ws.Cells(B, 8)
        If st1 = st2 Then
          ws.Cells(a, 13) = ws.Cells(a, 12) * ws.Cells(B, 12)
         
          Exit For

        End If
      Next B
    End If
  Next a
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
CountA only counts cells that are not blank?

I generally use the code below on a column that has the data in the furthest row
Code:
lngLastRow = Range("A" & Rows.Count).End(xlUp).Row
 
Upvote 0
Change this
Code:
cont = Application.WorksheetFunction.CountA(ws.Range("h:h"))
to
Code:
Cont = Ws.Range("H" & Rows.Count).End(xlUp).Row
 
Upvote 0

Forum statistics

Threads
1,214,406
Messages
6,119,330
Members
448,888
Latest member
Arle8907

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