Geekzone: technology news, blogs, forums
Guest
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
'

'
    Range("B7:F36").Select
    Selection.Copy
    Sheets("PO ").Select
    Range("A14").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("A2").Select
    Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
    Selection.Copy
End Sub

Hope it is of some use.


4005 posts

Uber Geek
+1 received by user: 698

Trusted
Subscriber

  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.
do
  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!

Cheers

13 posts

Geek


  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 »

Intel introduces new NUC kits and NUC mini PCs
Posted 16-Aug-2018 11:03


The Warehouse leaps into the AI future with Google
Posted 15-Aug-2018 17:56


Targus set sights on enterprise and consumer growth in New Zealand
Posted 13-Aug-2018 13:47


Huawei to distribute nova 3i in New Zealand
Posted 9-Aug-2018 16:23


Home robot Vector to be available in New Zealand stores
Posted 9-Aug-2018 14:47


Panasonic announces new 2018 OLED TV line up
Posted 7-Aug-2018 16:38


Kordia completes first live 4K TV broadcast
Posted 1-Aug-2018 13:00


Schools get safer and smarter internet with Managed Network Upgrade
Posted 30-Jul-2018 20:01


DNC wants a safer .nz in the coming year
Posted 26-Jul-2018 16:08


Auldhouse becomes an AWS Authorised Training Delivery Partner in New Zealand
Posted 26-Jul-2018 15:55


Rakuten Kobo launches Kobo Clara HD entry level reader
Posted 26-Jul-2018 15:44


Kiwi team reaches semi-finals at the Microsoft Imagine Cup
Posted 26-Jul-2018 15:38


KidsCan App to Help Kiwi Children in Need
Posted 26-Jul-2018 15:32


FUJIFILM announces new high-performance lenses
Posted 24-Jul-2018 14:57


New FUJIFILM XF10 introduces square mode for Instagram sharing
Posted 24-Jul-2018 14:44



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.