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

#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

  #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.

4683 posts

Uber Geek


  #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

  #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


  #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

News »

Freeview On Demand app launches on Sony Android TVs
Posted 6-Aug-2020 13:35

UFB hits more than one million connections
Posted 6-Aug-2020 09:42

D-Link A/NZ extends COVR Wi-Fi EasyMesh System series with new three-pack
Posted 4-Aug-2020 15:01

New Zealand software Rfider tracks coffee from Colombia all the way to New Zealand businesses
Posted 3-Aug-2020 10:35

Logitech G launches Pro X Wireless gaming headset
Posted 3-Aug-2020 10:21

Sony Alpha 7S III provides supreme imaging performance
Posted 3-Aug-2020 10:11

Sony introduces first CFexpress Type A memory card
Posted 3-Aug-2020 10:05

Marsello acquires Goody consolidating online and in-store marketing position
Posted 30-Jul-2020 16:26

Fonterra first major customer for Microsoft's New Zealand datacentre
Posted 30-Jul-2020 08:07

Everything we learnt at the IBM Cloud Forum 2020
Posted 29-Jul-2020 14:45

Dropbox launches native HelloSign workflow and data residency in Australia
Posted 29-Jul-2020 12:48

Spark launches 5G in Palmerston North
Posted 29-Jul-2020 09:50

Lenovo brings speed and smarter features to new 5G mobile gaming phone
Posted 28-Jul-2020 22:00

Withings raises $60 million to enable bridge between patients and healthcare
Posted 28-Jul-2020 21:51

QNAP integrates Catalyst Cloud Object Storage into Hybrid Backup solution
Posted 28-Jul-2020 21:40

Geekzone Live »

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

Support Geekzone »

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.