VBA problem

zyhin

Board Regular
Joined
Oct 8, 2009
Messages
78
Can someone tell me how I can refresh LastRow. It uses the same row for every sheet and I need it to be the LastRow for every sheet.

Code:
Dim TabNumber As Worksheet
 
For Each TabNumber In ActiveWorkbook.Worksheets
 
     If TabNumber.Name <> "Welcome" Then
 
          With TabNumber
 
                  Lastrow = Cells.Find(what:="*", searchdirection:=x1Previous, searchorder:=x1ByRows) .Row
                  TabNumber.Cells(LastRow, 6).Value = Time
                  TabNumber.Cells(LastRow, 7).Value = "h:mm:ss;@"
                  TabNumber.Cells(LastRow, 7).Formula = TabNumber.Cells(LastRow, 6) - TabNumber.Cells(LastRow, 5)
 
          End With
 
    End If
 
Next TabNumber

Z
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hello

I check the first three column:

Code:
Dim TabNumber As Worksheet
 
For Each TabNumber In ActiveWorkbook.Worksheets
 
     If TabNumber.Name <> "Welcome" Then
 
          With TabNumber
                Set AF = Application.WorksheetFunction
                Lastrow = AF.Max(TabNumber.Cells(Rows.Count, 1).End(xlUp).Row, _
                TabNumber.Cells(Rows.Count, 2).End(xlUp).Row, TabNumber.Cells(Rows.Count, 3).End(xlUp).Row)
                
                TabNumber.Cells(Lastrow, 6).Value = Time
                TabNumber.Cells(Lastrow, 7).Value = "h:mm:ss;@"
                TabNumber.Cells(Lastrow, 7).Formula = TabNumber.Cells(Lastrow, 6) - TabNumber.Cells(Lastrow, 5)
 
          End With
 
    End If
 
Next TabNumber
 
Upvote 0
Code:
    Dim TabNumber As Worksheet, Lastrow As Long
    
    For Each TabNumber In ActiveWorkbook.Worksheets
    
        With TabNumber
        
            If .Name <> "Welcome" Then
     
                Lastrow = [COLOR="Red"].[/COLOR]Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
                .Cells(Lastrow, 6).Value = Time
                .Cells(Lastrow, 7).NumberFormat = "h:mm:ss;@"
                .Cells(Lastrow, 7).Formula = .Cells(Lastrow, 6) - .Cells(Lastrow, 5)
     
            End If
     
        End With
     
    Next TabNumber
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,544
Members
452,925
Latest member
duyvmex

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