Find Next Empty Cell

temerson

New Member
Joined
Apr 22, 2019
Messages
39
Hello,

I have the following code:

Sub EmptyRow()




On Error Resume Next


Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Application.ScreenUpdating = False


Dim wbCurrent As Workbook
Dim wsCHINO As Worksheet
Dim wsSTOCKTON As Worksheet
Dim wsFLM As Worksheet
Dim wsDGV As Worksheet
Dim wsAURORA As Worksheet


Dim nLastCol, i As Integer


'KEEP CHINO COLUMNS
Set wbCurrent = ActiveWorkbook
Set wsCHINO = wbCurrent.Worksheets("CHINO")


nLastCol = wsCHINO.Cells.Find("*", LookIn:=xlValues, searchorder:=xlByColumns, searchdirection:=xlPrevious).Column




For i = nLastCol To 22 Step -1
If InStr(1, wsCHINO.Cells(12, i).Value, "", vbTextCompare) > 0 Then
Else
Value = "TOTAL CASES"
End If
Next i




End Sub

The end goal is:

1. loop through all the tabs and find the next empty cell in row 12.
2. Then add "Total Cases" in that empty cell.
3. put in a sum formula and autofill down.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
37,042
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Does this macro do what you want...
Code:
Sub TotalCases()
  Dim LastCol As Range, WS As Worksheet
  For Each WS In Worksheets
    Set LastCol = WS.Rows(12).Find("*", , xlValues, , xlByColumns, xlPrevious)
    If Not LastCol Is Nothing Then
      If LastCol.Column > 22 Then Cells(12, LastCol.Column + 1).Value = "Total Cases"
    End If
  Next
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,133,271
Messages
5,657,757
Members
418,411
Latest member
Excellency

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
Top