Geekzone: technology news, blogs, forums
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.

453 posts

Ultimate Geek
+1 received by user: 27

Topic # 26765 2-Oct-2008 15:17
Send private message

I hope this is the right forum for this Laughing

I've got a macro in a sheet thats used for copying some data from one sheet to another. And yes I'm very new to this!

Sub copy_to_po()
' copy_to_po Macro

    Sheets("PO ").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Ordering Sheet").Select
End Sub

The problem that I have is that the range is dynamic. It always starts at B7 and goes no further than column F, however the row varies based on data that is entered in column E. Its always in order, its just a case of saying stop the selection at the row where there is no more data in column E.

Thanks in advance!

Create new topic
91 posts

Master Geek

  Reply # 168658 2-Oct-2008 16:38
Send private message

I use the following to select the data on one tab so that it can be copied to a database. Data is dynamic in respect to number of rows but constant for number of columns. I am using Office 2007 but the macro runs on *.xls files so should be OK. Recorded the macro by holding down the shift key and doing a ctrl/end to highlight all active cells.

Sub Select_Copy()
' Select_Copy Macro
' Select and copy an area.

    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
End Sub

Hope it is of some use.

4164 posts

Uber Geek
+1 received by user: 760


  Reply # 168661 2-Oct-2008 16:57
Send private message

If I want to count the number of consecutive populated rows in a worksheet I would do something like this:

dim countRows as integer
countRows = 6 'When this ticks over below we'll be starting at row 7.
  countrows = countrows + 1
loop until worksheets("Ordering Sheet").cells(countrows + 1 , 5) = "" 'Column 5 is column E.

Then the first line of your code would be:

Range("B" + cstr(countRows) + ":F36").Select

You just need to be careful that you don't have any blanks anywhere in column E.


453 posts

Ultimate Geek
+1 received by user: 27

  Reply # 168667 2-Oct-2008 17:23
Send private message

Thanks guys.

The first one kind of worked - second worked perfectly with some minor tweaking!


14 posts


  Reply # 174330 29-Oct-2008 11:24
Send private message

Another way to do this is to use a named range for the data in the source sheet.
the advantage of using named ranges in macros is that the reference remains correct if it is moved around in the referenced sheet.
If you named the range B7:F37 "SourceData" then the code to copy it would be:ActiveSheet.Range(“SourceData”).SelectSelection.Copy ..etcNote the named range is one row deeper than the data entries.This is so when you add to the range it is included in the named range.Select the last blank row, select down the number of new rows you want to add and ‘Insert Rows’.This does copy an extra blank row into the destination range and it may not be so good if adding rows into the source sheet is a problem.

Create new topic

Twitter »

Follow us to receive Twitter updates when new discussions are posted in our forums:

Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:

Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:

Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.

Geekzone Live »

Our community of supporters help make Geekzone possible. Click the button below to join them.

Support Geezone on PressPatron

Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.