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.

3838 posts

Uber Geek
+1 received by user: 617


  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!


13 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:

News »

Stuff Pix enters streaming video market
Posted 21-Mar-2018 09:18

Windows no longer Microsoft’s main focus
Posted 13-Mar-2018 07:47

Why phone makers are obsessed with cameras
Posted 11-Mar-2018 12:25

New Zealand Adopts International Open Data Charter
Posted 3-Mar-2018 12:48

Shipments tumble as NZ phone upgrades slow
Posted 2-Mar-2018 11:48

Oppo R11s: high-end Android, budget price
Posted 27-Feb-2018 16:27

Samsung New Zealand introducing the Galaxy S9 and S9+
Posted 26-Feb-2018 07:00

Fujifilm X beats its best with new top of the range, high-performance camera
Posted 24-Feb-2018 14:05

One million kiwis affected by cybercrime
Posted 24-Feb-2018 13:58

New Zealanders want to engage with government online and via mobile apps
Posted 24-Feb-2018 13:56

Samsung launches Samsung Max
Posted 24-Feb-2018 13:52

CPTPP text and National Interest Analysis released for public scrutiny
Posted 21-Feb-2018 19:43

Foodstuffs to trial digitised shopping trolleys
Posted 21-Feb-2018 18:27

2018: The year of zero-login, smart cars & the biometrics of things
Posted 21-Feb-2018 18:25

Intel reimagines data centre storage with new 3D NAND SSDs
Posted 16-Feb-2018 15:21

Geekzone Live »

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

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.