Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA loop until eof

Hi All,

I'm a big time Newbie.

I have had a look into DO LOOP but I must say I'm a bit lost.

I would like to loop the following untill end of file.

Please Help

Sub Sheet_2()
'Find copy and move to new cell.
'
Cells.Find(What:="define", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False).Activate
'
Selection.Copy
ActiveCell.Offset(0, 2).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
End Sub


Thanks

Wombatz


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Excel VBA loop until eof

I'm not sure what you want (as far as copying and
pasting), but this is a Do Loop that might help you. This
is one of my earlier methods of programming when I started
doing Excel VBA many years ago. It reminds me of Fortran
IV programming that I studied - that's why I started out
this way.

Sub DoLoop()
Dim X As Integer
X = 0

Do Until X 100
X = X + 1
ActiveCell.Offset(1, 0).Select
If ActiveCell.Offset(0, 0).Value = "Hi" Then
GoTo MessageFoundIt
End If
Loop

Exit Sub
MessageFoundIt:
MsgBox "You found Hi at row number " & _
ActiveCell.Offset(0, 0).Row & ".", _
vbInformation, "Found It"
End Sub

-----Original Message-----
Hi All,

I'm a big time Newbie.

I have had a look into DO LOOP but I must say I'm a bit

lost.

I would like to loop the following untill end of file.

Please Help

Sub Sheet_2()
'Find copy and move to new cell.
'
Cells.Find(What:="define", After:=ActiveCell,

LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False).Activate
'
Selection.Copy
ActiveCell.Offset(0, 2).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste
End Sub


Thanks

Wombatz


---
Message posted from http://www.ExcelForum.com/

.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA loop until eof

Hi Rick,

I'm ok with the copy and past part.

The word DEFINE in the Cells.Find(What:= is all the way through th
file. this file is very big and all i need to do is copy what is in th
DEFINE cell to a new cell.
i need the loop to search the file until it's comes to end of file an
stop

eg:

DEFINE RECORD CUSTOMER 784
data (this data could be anything from numbers to statments)
data
DEFINE RECORD CUSTOMER 187
data
data
DEFINE RECORD CUSTOMER 234

Thank

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Excel VBA loop until eof

Wombatz

Assuming that the "define" is always in column A, then the following should get you going. It will put the contents of the cell containing the word "define" 2 cells to the right.

Sub bbb()
With Columns("a:a")
Set c = .Find("define")
If Not c Is Nothing Then
firstaddr = c.Address
Range(c.Address).Offset(0, 2).Value = c.Value
Set c = .FindNext(c)
While Not c Is Nothing And c.Address < firstaddr
Range(c.Address).Offset(0, 2).Value = c.Value
Set c = .FindNext(c)
Wend
End If
End With
End Sub

Tony
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA loop until eof

Thanks Tony,

this is good.

could you help with one more thing.
i need to copy the define statment into the next 8 cells below

Thanks

Wombat

--
Message posted from http://www.ExcelForum.com



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Excel VBA loop until eof

Wombatz

Try this.

Tony

Sub bbb()
With Columns("a:a")
Set c = .Find("define")
If Not c Is Nothing Then
firstaddr = c.Address
For i = 0 To 7
Range(c.Address).Offset(i, 2).Value = c.Value
Next i
Set c = .FindNext(c)
While Not c Is Nothing And c.Address < firstaddr
For i = 0 To 7
Range(c.Address).Offset(i, 2).Value = c.Value
Next i
Set c = .FindNext(c)
Wend
End If
End With
End Sub
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
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
Loop in Excel Mike Excel Discussion (Misc queries) 1 January 10th 08 05:35 PM
VB for excel, how do I loop through code steve hobden via OfficeKB.com Excel Discussion (Misc queries) 2 June 9th 05 01:59 PM
Loop within Excel Formula? Dan[_29_] Excel Programming 3 December 23rd 03 10:26 PM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


All times are GMT +1. The time now is 10:37 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"