ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Loop Macro (https://www.excelbanter.com/excel-programming/343486-loop-macro.html)

Brian Matlack[_16_]

Loop Macro
 

Hi!
I don't yet understand loop macros but I'd like to.
I am importing a text file that is a variable number of data group
that also vary in length (rows). The groups are separated by 2 blan
rows and the data in each group is contiguous.
How can I select these groups and process them when I don't always kno
how many there are or how long they are.
Thanks

--
Brian Matlac
-----------------------------------------------------------------------
Brian Matlack's Profile: http://www.excelforum.com/member.php...nfo&userid=350
View this thread: http://www.excelforum.com/showthread.php?threadid=47828


Bernie Deitrick

Loop Macro
 
Brian,

You need to loop through the areas collections of the filled cells. See the macro below for an
example, which assumes that your filled cells are constants.

HTH,
Bernie
MS Excel MVP

Sub Macro2()
Dim myCell As Range
Dim myArea As Range
Dim myData As Range

Set myData = Cells.SpecialCells(xlCellTypeConstants, 23)

For Each myArea In myData.Areas
MsgBox myArea.Address & " has " & myArea.Cells.Count & " cells."
'Process areas here
For Each myCell In myArea.Cells
'use this inner loop to process through the cells
Next myCell
Next myArea
End Sub


"Brian Matlack" wrote in message
news:Brian.Matlack.1x9hud_1129914323.4604@excelfor um-nospam.com...

Hi!
I don't yet understand loop macros but I'd like to.
I am importing a text file that is a variable number of data groups
that also vary in length (rows). The groups are separated by 2 blank
rows and the data in each group is contiguous.
How can I select these groups and process them when I don't always know
how many there are or how long they are.
Thanks!


--
Brian Matlack
------------------------------------------------------------------------
Brian Matlack's Profile: http://www.excelforum.com/member.php...fo&userid=3508
View this thread: http://www.excelforum.com/showthread...hreadid=478288





All times are GMT +1. The time now is 01:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com