Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
I would like to perform a macro on multiple spreadsheets with varying numbers
of rows. When recording the macro, I used the keystrokes to go to the end of the spreadsheet; however, when I apply the macro to other spreadsheets, it uses a fixed row area. How can I get this to go to the end of the spreadsheet? tlwhite Range("A2").Select ActiveCell.SpecialCells(xlLastCell).Select Range(Selection, Cells(1)).Select Range("B1:M2028").Select Range("M2028").Activate |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi,
The macro below will loop through the named sheets and find the last row in column A of each sheet. Sub Sonic() Dim V As Variant Dim S As String Dim Sh As Worksheet Dim LastRow As Long S = "Sheet1,Sheet2,Sheet3" V = Split(S, ",") For Each Sh In ThisWorkbook.Worksheets If Not IsError(Application.Match(CStr(Sh.Name), V, 0)) Then 'This line finds the last row on column A LastRow = sh.Cells(Cells.Rows.Count, "A").End(xlUp).Row End If Next Sh End Sub -- Mike When competing hypotheses are otherwise equal, adopt the hypothesis that introduces the fewest assumptions while still sufficiently answering the question. "tlwhite" wrote: I would like to perform a macro on multiple spreadsheets with varying numbers of rows. When recording the macro, I used the keystrokes to go to the end of the spreadsheet; however, when I apply the macro to other spreadsheets, it uses a fixed row area. How can I get this to go to the end of the spreadsheet? tlwhite Range("A2").Select ActiveCell.SpecialCells(xlLastCell).Select Range(Selection, Cells(1)).Select Range("B1:M2028").Select Range("M2028").Activate |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Sub lastrowineachsht()
'On Error Resume Next For i = 1 To Sheets.Count With Sheets(i) 'MsgBox Sheets(i).Name lr = .Cells.Find("*", Cells(Rows.Count, Columns.Count) _ , , , xlByRows, xlPrevious).Row 'MsgBox lr ..Range("B1:M" & lr).Interior.ColorIndex = 16 'Select End With Next i End Sub -- Don Guillett Microsoft MVP Excel SalesAid Software "tlwhite" wrote in message ... I would like to perform a macro on multiple spreadsheets with varying numbers of rows. When recording the macro, I used the keystrokes to go to the end of the spreadsheet; however, when I apply the macro to other spreadsheets, it uses a fixed row area. How can I get this to go to the end of the spreadsheet? tlwhite Range("A2").Select ActiveCell.SpecialCells(xlLastCell).Select Range(Selection, Cells(1)).Select Range("B1:M2028").Select Range("M2028").Activate |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Group Excel data in varying length financial periods 4/5 weeks | Excel Discussion (Misc queries) | |||
Web Query from multiple varying length pages | Excel Worksheet Functions | |||
using VB to read in a column of values of varying length into an array | Excel Worksheet Functions | |||
Excel 2003: In a Macro,how to select a variable row length table | Excel Discussion (Misc queries) | |||
extracting data from a text string of varying length | Excel Discussion (Misc queries) |