#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 6
Default Macro looping?

How do I code a macro so that it loops until it goes through all of the
information on the excel file? This way I do not have to rewrite the same
code for 20 lines one day and then 30 lines the next day.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,522
Default Macro looping?

sub loopit()
lastrow=cells(rows.count,"a").end(xlup).row
for i= 1 to lastrow
cells(i,1)=??
next i
end sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"klh84" wrote in message
...
How do I code a macro so that it loops until it goes through all of the
information on the excel file? This way I do not have to rewrite the same
code for 20 lines one day and then 30 lines the next day.


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,276
Default Macro looping?

Hi,
something like this maybe

Dim rng1 As Range

' To start statement to delete rows
Worksheets("Projects").Select

With ThisWorkbook.Sheets("Projects")

With Columns("e")

Do

Set rng1 = .Find(Me.TxtProjectCode.Value, LookIn:=xlValues,
LookAt:=xlWhole, _
MatchCase:=False)

If rng1 Is Nothing Then Exit Do

rng1.EntireRow.Delete


Loop

End With

End With


"klh84" wrote:

How do I code a macro so that it loops until it goes through all of the
information on the excel file? This way I do not have to rewrite the same
code for 20 lines one day and then 30 lines the next day.

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 7,247
Default Macro looping?

You must first define what consitutes the "end" of the worksheet. If
you have data in column A and you want to loop through column A until
a blank cell is encountered, use something like

Dim R As Range
Set R = Worksheets("Sheet1").Range("A1")
Do Until R.Value = vbNullString
' do something with R
Set R = R(2, 1)
Loop


Or, if you can define one column whose last non-blank cell indicates
the end of the worksheet, you can use something like

Dim WS As Worksheet
Dim Col As String
Dim LastRow As Long
Dim StartRow As Long
Dim RowNdx As Long

Set WS = Worksheets("Sheet1") '<<<<
Col = "K" '<<<<
StartRow = 1 '<<<<
With WS
LastRow = .Cells(.Rows.Count, Col).End(xlUp).Row
For RowNdx = StartRow To LastRow
.Cells(RowNdx, "A").Value = whatever
Next RowNdx
End With


There are any number of other ways of defining what constitutes the
"end" of a worksheet. You might want to be more specific about what
you really need.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com






On Thu, 25 Feb 2010 10:46:01 -0800, klh84
wrote:

How do I code a macro so that it loops until it goes through all of the
information on the excel file? This way I do not have to rewrite the same
code for 20 lines one day and then 30 lines the next day.

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
Looping Macro KimC Excel Discussion (Misc queries) 1 January 11th 10 04:55 AM
Looping Macro Jase Excel Discussion (Misc queries) 5 March 12th 08 09:08 PM
Looping macro RK Excel Worksheet Functions 2 December 12th 06 11:29 PM
Looping a macro Sony Excel Discussion (Misc queries) 3 October 30th 06 11:52 AM
Macro looping problem. [email protected] Excel Discussion (Misc queries) 8 October 26th 06 02:44 PM


All times are GMT +1. The time now is 04:06 AM.

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"