Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Copying data ranges in a macro

Here is my problem. I have 15 pages of data entry that
use cells B10-ck343 on each page. The cells are full of
vlookup's and equations if data is entered. I am trying
to write a macro that will copy only the rows I have
entered data into on the 15 pages unto 1 page for export
to access. the same number of rows will be on each page.
The problem is that I can not figure out how to copy and x
number of rows instead of the entire block. Right now I
only have data entered in rows 10-14 but copying the cells
with a [end][downarrow] picks up the blank formula rows as
well. HELP Please!

Chris
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Copying data ranges in a macro

One way is to use an array formula in your code that determines the last row
with a value different from "".

Option Explicit
Sub testme01()

Dim LastRow As Long
Dim wks As Worksheet
Dim toWks As Worksheet
Dim destCell As Range

Set toWks = Worksheets.Add

For Each wks In ActiveWorkbook.Worksheets
With wks
If .Name = toWks.Name Then
'do nothing
Else
LastRow = .Evaluate("Max(Row(B10:ck343)*(b10:ck343<""""))")
If LastRow = 0 Then
'nodata
Else
With toWks
Set destCell = .Cells(.Rows.Count, "B").End(xlUp)
End With
If IsEmpty(destCell) Then
'do nothing
Else
Set destCell = destCell.Offset(1, 0)
End If

.Range("B10:ck" & LastRow).Copy _
Destination:=destCell
End If
End If
End With
Next wks
End Sub

If you put this formula in a cell on your worksheet:
=MAX(ROW(B10:CK343)*(B10:CK343<""))
but hit ctrl-shift-enter instead of just enter (it's an array formula), you'll
see that it evaluates to the last row that looks filled.

I used column B as my "main" column. I expect something there first.

"Chris B." wrote:

Here is my problem. I have 15 pages of data entry that
use cells B10-ck343 on each page. The cells are full of
vlookup's and equations if data is entered. I am trying
to write a macro that will copy only the rows I have
entered data into on the 15 pages unto 1 page for export
to access. the same number of rows will be on each page.
The problem is that I can not figure out how to copy and x
number of rows instead of the entire block. Right now I
only have data entered in rows 10-14 but copying the cells
with a [end][downarrow] picks up the blank formula rows as
well. HELP Please!

Chris


--

Dave Peterson

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
macro error - copying data twice Gretta Excel Discussion (Misc queries) 1 April 6th 07 08:14 PM
macro error - copying data twice Gretta Excel Discussion (Misc queries) 1 April 6th 07 04:40 PM
Macro for copying conditional data ipsy9 Excel Worksheet Functions 0 June 8th 06 08:19 PM
Macro Help - Copying and appending data Louis Markowski Excel Worksheet Functions 1 September 16th 05 06:53 PM
Copying ranges of data between worksheets Christopher R. Lee Excel Worksheet Functions 0 February 3rd 05 08:56 PM


All times are GMT +1. The time now is 12:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"