View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
L. Howard L. Howard is offline
external usenet poster
 
Posts: 852
Default For Each sheet in WkBook problem

On Thursday, November 26, 2015 at 6:11:01 PM UTC-8, GS wrote:
On Thursday, November 26, 2015 at 5:03:00 PM UTC-8, GS wrote:
My bad! (aircode<g)

This..
lNextRow = .Cells(1, .Rows.Count).End(xlUp).Row + 1

..should be...

lNextRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1

--
Garry


Hi Garry,

Thanks, actually if I had studied the code harder, I should have seen
that.

I did have to make a change on this line for the Resize columns.

.Cells(lNextRow, 1).Resize(UBound(vData), 4) = vData

Works great now.

Thanks for the array approach, I like the array shot at it, but it
still whacks me most often.

Howard


Why did you hardcode the cols? The code uses the cols in vData, which
is 4 based on your range of A:D! You should always let the code use the
array sizes for the data...

Ubound(vData), 2) = 4 since it specifies the 2nd dim (#cols)

..because the range it holds spans cols A:D. You likely forgot that
loading a worksheet range into a variant results a 2D array.

I don't even use hard values for the source range because the data
resides in a dynamic range named "InputData" on every sheet. I didn't
want to take you there with this thread in case it went over your head,
but I do this...

vData = wks.Range("InputData")

..so the code is 100% reusable as well as better self-documenting.

HTH

--
Garry



Only changed it because that line erroed out, I tried 4 and it works with the 4.

Howard