View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Looping through my worksheet and copying cells

Since you're posting in plain text (thank you), none of the lines show up in
red.

Just add above the line you need an explanation for.

a94andwi wrote:

Hello again.

Now I have finally found out some way to loop through my files but
there are still some major functions I can't understand how to solve.

Here's the loop:

Do While FNames < ""

'SourceRcount = SourceRange.Rows.Count

Set myBook = Workbooks.Open(FNames)

Set SourceRange = myBook.Worksheets(1).Range("A4:L20")

SourceRcount = SourceRange.Rows.Count

'Set destrange = basebook.Worksheets(1).Cells(counter, "O")
Set destrange = basebook.Worksheets(1).Range("A4")

'Skriv in arbetsbokens namn i kolumn H
basebook.Worksheets(1).Cells(counter, "M").Value = myBook.Name
If myBook.Worksheets(1).Range("L1") = Date Then

'SourceRange.Copy destrange
' Instead of this line you can use the code below to copy only
the values

With SourceRange
'Set destrange = basebook.Worksheets(1).Cells(counter,
"O"). _
Resize(.Rows.Count,
Columns.Count)
Set destrange = basebook.Worksheets(1).Range("A4"). _
Resize(.Rows.Count, .Columns.Count)
End With
destrange.Value = SourceRange.Value
End If

myBook.Close False

counter = counter + SourceRcount
FNames = Dir()

Loop

The lines written in red above are where I have difficulties.

On every new worksheet I want only the rows which has some values
copied onto the destination worksheet.
On the destination worksheet I want the first copied values to be
copied to Cell A4 and the next values on the cells A5, A6 and so on.
When the loop continues to the next file and copies the values I want
it to continue to copy the values the next empty cell in the
destination worksheet.

Anyone who can help me?

/anders

--
a94andwi
------------------------------------------------------------------------
a94andwi's Profile: http://www.excelforum.com/member.php...o&userid=21077
View this thread: http://www.excelforum.com/showthread...hreadid=386117


--

Dave Peterson