Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default varying table length in a MACRO

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default varying table length in a MACRO

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,522
Default varying table length in a MACRO

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Group Excel data in varying length financial periods 4/5 weeks ml123 Excel Discussion (Misc queries) 2 March 19th 08 12:58 PM
Web Query from multiple varying length pages Jeffshex Excel Worksheet Functions 3 August 24th 07 11:21 PM
using VB to read in a column of values of varying length into an array [email protected] Excel Worksheet Functions 2 June 12th 06 10:08 PM
Excel 2003: In a Macro,how to select a variable row length table Tonto Excel Discussion (Misc queries) 1 June 1st 05 03:47 PM
extracting data from a text string of varying length andy from maine Excel Discussion (Misc queries) 4 March 28th 05 07:11 PM


All times are GMT +1. The time now is 05:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"