View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default For Each Loop not working properly

You gave no indication in your original code where to copy the data, so
This copies the data to the next sheet after UHU a line at a time (make sure
UHU isn't the last sheet in the tab order and one after it is blank).
Sub Unit_Hourly_Updates()
Dim Unit As Range
Sheet("UHU").Next.Activate
Range("A1").Select
For Each Unit In Sheets("UHU").Range("B7:B24")
Sheets("UHU").Activate
unit.offset(0,1).Resize(1,5).Select
' msgbox "Selection is: " & selection.Address
selection.copy
sheets("UHU").Next.Activate
Sheets("UHU").Paste
ActiveCell.Offset(1,0).Select
Next Unit
End Sub

the alternative off course
Sub copyDate()

Sheets("UHU").Range("B7:B24").offset(0,1).Resize(, 5).Copy _
Destination:= Sheets("UHU").Next.Range("A1")
End sub


--
Regards,
Tom Ogilvy


"oakman" wrote:


Greetings to all,
I would like to thank people in advance for any help that may be given.
I am very grateful! Here is my problem: I have a list of units with
data next to them. So far, all that I am trying to do is to go through
each of these units and select a range of data next to it. I can get
the macro to select the range of data for the first unit. The loop
should go to the next unit and copy the same range of data as the one
above. However, this does not happen at all. Any help is REALLY
appreciated! Thank you

Sub Unit_Hourly_Updates()
Dim Unit As Variant
Unit = Sheets("UHU").Range("B7:B24")
For Each Unit In Sheets("UHU").Range("B7:B24")
Sheets("UHU").Activate
Range("C7:G7").Select
Next Unit
End Sub


--
oakman
------------------------------------------------------------------------
oakman's Profile: http://www.excelforum.com/member.php...fo&userid=9172
View this thread: http://www.excelforum.com/showthread...hreadid=525659