Copy & Paste Problem

Please post any questions regarding the program here.

Moderator: 2020vision

Copy & Paste Problem

Postby MartinP_uk » Fri Mar 26, 2010 10:04 pm

The code below copies and paste O5:O14 into Y5:Y14. However it also pastes into S5:S:14 which i do not require. Any idea how i can stop the pasting in column S please?

Code: Select all
 Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim NextCol As Long
Application.EnableEvents = False

NextCol = Cells(Target.Row, Columns.Count).End(xlToLeft).Column + 1

Range("O5:O14").Copy
Cells(5, NextCol).PasteSpecial Paste:=xlPasteValues
Application.EnableEvents = True
End Sub
User avatar
MartinP_uk
 
Posts: 41
Joined: Wed Nov 28, 2007 8:41 am

Postby osknows » Fri Mar 26, 2010 10:26 pm

Are you trying to paste into the same Y5:Y14 every time or Y5:Y14, Z5:Z14, AA5:AA14...etc?
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby MartinP_uk » Fri Mar 26, 2010 10:28 pm

Y5:Y14, Z5:Z14, AA5:AA14...etc? thats correct m8.
User avatar
MartinP_uk
 
Posts: 41
Joined: Wed Nov 28, 2007 8:41 am

Postby osknows » Fri Mar 26, 2010 10:44 pm

There's a few ways to do this, perhaps easiest method is

this in a MODULE
Code: Select all
Public Nextcol As Integer


and this in the SHEET

Code: Select all
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False

If Nextcol >= 200 Then
Nextcol = 0
End If

ThisWorkbook.Sheets(Target.Worksheet.Name).Range("y5:y14").Offset(0, Nextcol).Value = _
ThisWorkbook.Sheets(Target.Worksheet.Name).Range("o5:o14").Value
Nextcol = Nextcol + 1
Application.EnableEvents = True
End Sub


Nextcol will increment to 200 before resetting to 0, so that gives you column Y(0) to HQ(200) before resetting back to column Y
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby MartinP_uk » Sat Mar 27, 2010 9:03 am

Thank you osknows your knowledge of this kind of things seems to be fast 8) cheers :)
User avatar
MartinP_uk
 
Posts: 41
Joined: Wed Nov 28, 2007 8:41 am


Return to Help

Who is online

Users browsing this forum: No registered users and 60 guests

Sports betting software from Gruss Software


The strength of Gruss Software is that it’s been designed by one of you, a frustrated sports punter, and then developed by listening to dozens of like-minded enthusiasts.

Gruss is owned and run by brothers Gary and Mark Russell. Gary discovered Betfair in 2004 and soon realised that using bespoke software to place bets was much more efficient than merely placing them through the website.

Gary built his own software and then enhanced its features after trialling it through other Betfair users and reacting to their improvement ideas, something that still happens today.

He started making a small monthly charge so he could work on it full-time and then recruited Mark to help develop the products and Gruss Software was born.

We think it’s the best of its kind and so do a lot of our customers. But you can never stand still in this game and we’ll continue to improve the software if any more great ideas emerge.