LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy destination problem


Hi,
I have a routine that reads the selections made in a Listbox and
transfers the ranges on wks1 associated with those selections to wks2.
The problem I'm having is when there are multiple selections, the first
range will copy in the correct place, but then the subsequent ranges one
by one overwrite the first range. I need them to start pasting at Row 20
Column D and if the first range is 30 rows the next range would skip a
row and paste at Row 51 Column D. Here's my code including the code for
the listbox UserForm.

Option Explicit
Sub UserForm_Initialize()
Dim Cell As Range

ListBox1.Clear
For Each Cell In Range("ScopeTitles")
ListBox1.AddItem Cell.Value
Next
End Sub
Private Sub cmdCancel_Click()
SelectScopesForm.Hide
End Sub

Private Sub cmdInsertScopes_Click()
Dim SelCount, i As Integer
Dim ScopePicks() As Integer
Dim RCount, r, c As Long
Dim wks1 As Worksheet
Dim wks2 As Worksheet

Set wks1 = Worksheets("Scopes")
Set wks2 = Worksheets("Proposal")
' Hide the userform
SelectScopesForm.Hide
' Get count on rows
RCount = wks1.UsedRange.Rows.Count
SelCount = 0
For i = 0 To SelectScopesForm.ListBox1.ListCount - 1
If SelectScopesForm.ListBox1.Selected(i) Then
SelCount = SelCount + 1
If i = 0 Then
ReDim ScopePicks(i + 1)
Else
ReDim Preserve ScopePicks(SelCount)
End If
ScopePicks(SelCount - 1) = i + 1
End If
Next i
If SelCount 0 Then
' Loop through array and copy data from scopes selected
' in ListBox from Scopes worksheet to Proposal worksheet
For c = 0 To SelCount - 1
For r = 1 To RCount
' Here is the problem
wks2.Cells(r + 19, 4) = wks1.Cells(r, ScopePicks(c))
Next r
Next c
Else
MsgBox ("You didn't select any scopes.")
Exit Sub
End If
End Sub


--
Casey


------------------------------------------------------------------------
Casey's Profile: http://www.excelforum.com/member.php...fo&userid=4545
View this thread: http://www.excelforum.com/showthread...hreadid=515848

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using copy and destination formatting Jeff S.[_2_] Excel Discussion (Misc queries) 6 August 18th 09 11:24 AM
VBA .copy destination jerredjohnson Excel Discussion (Misc queries) 2 July 18th 06 11:18 PM
copy destination values Pete[_23_] Excel Programming 1 March 22nd 05 04:40 PM
Range.Copy (Destination) Garry Douglas Excel Programming 3 January 3rd 05 03:02 PM
Selection.Copy Destination:= Mike Fogleman Excel Programming 3 January 10th 04 02:18 AM


All times are GMT +1. The time now is 09:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"