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.

3925 posts

Uber Geek
+1 received by user: 660


  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 »

N4L helping TAKA Trust bridge the digital divide for Lower Hutt students
Posted 18-Jun-2018 13:08

Winners Announced for 2018 CIO Awards
Posted 18-Jun-2018 13:03

Logitech Rally sets new standard for USB-connected video conference cameras
Posted 18-Jun-2018 09:27

Russell Stanners steps down as Vodafone NZ CEO
Posted 12-Jun-2018 09:13

Intergen recognised as 2018 Microsoft Country Partner of the Year for New Zealand
Posted 12-Jun-2018 08:00

Finalists Announced For Microsoft NZ Partner Awards
Posted 6-Jun-2018 15:12

Vocus Group and Vodafone announce joint venture to accelerate fibre innovation
Posted 5-Jun-2018 10:52 to launch Kogan Mobile in New Zealand
Posted 4-Jun-2018 14:34

Enable doubles fibre broadband speeds for its most popular wholesale service in Christchurch
Posted 2-Jun-2018 20:07

All or Nothing: New Zealand All Blacks arrives on Amazon Prime Video
Posted 2-Jun-2018 16:21

Innovation Grant, High Tech Awards and new USA office for Kiwi tech company SwipedOn
Posted 1-Jun-2018 20:54

Commerce Commission warns Apple for misleading consumers about their rights
Posted 30-May-2018 13:15

IBM leads Call for Code to use cloud, data, AI, blockchain for natural disaster relief
Posted 25-May-2018 14:12

New FUJIFILM X-T100 aims to do better job than smartphones
Posted 24-May-2018 20:17

Stuff takes 100% ownership of Stuff Fibre
Posted 24-May-2018 19:41

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.