Indirect Funtion to retrieve last cell with Data

PVA0724

New Member
Joined
Apr 21, 2012
Messages
48
Hi

Thanks to the help I was able to built a code that retreives the worksheet name in column 5, now I was looking -but I din't find - a way to have the Indirect funtion to point the sheet name and in addition to retrieve the last cell with data in a specific column (that changes based on the worksheet).

Any assistance will be more than welcome

The code I have is this one

Code:
Sub Summary()
Dim wks As Worksheet
ultl = Sheets("Control").Cells(1048576, 4).End(xlUp).Row
i = 31
For Each wks In Worksheets(Array("Emergencias  Bancomer", "Emergencias Banamex", "Emergencias Cheques", _
"Rentas Transfer", "Rentas Cheques", "Indemnizaciones", "Indemnizaciones Cheque", "Banamex Automaticos", _
"Cheques", "Bancomer", "Cajas", "Anticipos Empleados", "USD", "EUR", "Secretarias", "Luz", "Agua"))
 
     If wks.Visible Then
     Sheets("Control").Cells(i, 5) = wks.Name
     Sheets("Control").Cells(i, 6) = ' Application.Worksheetfuntion.Indirect (cells(i, 5) & last active cell of column x from the visible workshet
     i = i + 1
     End If
     
Next wks
End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Hi,

I think you mentioned in your other post that the array was a list of all your worksheets except "Control". If so you can perhaps simplify it to something like this:

Code:
Sub example()

    Dim wks As Worksheet
    Dim i   As Long


    i = 31 ' start row
    For Each wks In Worksheets
        With Sheets("Control")
            If wks.Name <> .Name Then
                If wks.Visible = xlSheetVisible Then
                    .Cells(i, 5) = wks.Name
                    .Cells(i, 6) = wks.Cells(wks.Rows.Count, 5).End(xlUp).Value ' change to .Row if you want the row number rather than cell value
                    i = i + 1
                End If
            End If
        End With
    Next wks


End Sub
Note that this will return the cell value in row 1 if the whole column is empty so you will need to tweak it a little if you need to handle that situation differently.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

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