Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Sub to copy n paste special discontiguous ranges from 1 sht to ano


Seeking help to modify the sub below
to resolve the issues (1) & (2) remarked
Thanks for insights

Sub CopyPaste1()
Sheets("Credit MIS").Range("H7:H10").Copy
Sheets("Asia").Select
Range("IV7").Select
Selection.End(xlToLeft).Select
'(1). need the selection above to offset 1 col to the right

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False

'(2). need to repeat the above copy n paste operation
'for other source ranges in "Credit MIS" viz:
'H14:H17
'H21:H28
'H31
'H35:H38
'H42:H48
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Sub to copy n paste special discontiguous ranges from 1 sht to ano


I don't know what determines each set of ranges. I assumed there was a blnk
in column H "Credit MIS" top determine the where each range ends. See if
this helps.

Sub CopyPaste1()

RowCount = 2
StartRow = RowCount
With Sheets("Credit MIS")
'check if there is a blank in column H
If .Range("H" & (RowCount + 1)) = "" Then

.Range("H" & StartRow & ":H" & RowCount).Copy

With Sheets("Asia")
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
LastCol = .Cells(LastRow, Columns.Count).End(xlToLeft)
.Cells(7, LastCol + 1).PasteSpecial _
Paste:=xlPasteValues
End With
'add two to skip blank in column H
StartRow = RowCount + 2
End If

RowCount = RowCount + 1
End With

End Sub



"Max" wrote:

Seeking help to modify the sub below
to resolve the issues (1) & (2) remarked
Thanks for insights

Sub CopyPaste1()
Sheets("Credit MIS").Range("H7:H10").Copy
Sheets("Asia").Select
Range("IV7").Select
Selection.End(xlToLeft).Select
'(1). need the selection above to offset 1 col to the right

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False

'(2). need to repeat the above copy n paste operation
'for other source ranges in "Credit MIS" viz:
'H14:H17
'H21:H28
'H31
'H35:H38
'H42:H48
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Sub to copy n paste special discontiguous ranges from 1 sht to


Joel, thanks for your response. The earlier problem was the intervening
merged rows in-between in the source sheet: Credit MIS and in the destination
sheet: Asia. I've removed all of the merged rows and basically just want to
do this:

Copy the range H7:H48 in Credit MIS (it's a fixed range to copy)
Paste special as values into "Asia"'s next available col range,
to the right of the last filled col range,
starting the paste identically in row 7
(eg if last filled col range in Asia is G7:G48, sub to paste it into H7:H48)

Grateful if you could help with a sub to do the above
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Sub to copy n paste special discontiguous ranges from 1 sht to


Hi Max

Try if this is what you need:

Sub CopyPaste1()
Dim shA As Worksheet
Dim shB As Worksheet

Set shA = Sheets("Credit MIS")
Set shB = Sheets("Asia")
CopyFromRngArray = Split(("H7:H10, H14:H17, H21:H28, H31, H35:H38,
H42:H48"), ",")
NextCol = shB.Range("IV7").End(xlToLeft).Column + 1

For c = 0 To UBound(CopyFromRngArray)
DestRow = Range(CopyFromRngArray(c)).Cells(1, 1).Row
shA.Range(CopyFromRngArray(c)).Copy
shB.Cells(DestRow, NextCol).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Next
Application.CutCopyMode = False
End Sub

Best regards,
Per

"Max" skrev i meddelelsen
...
Joel, thanks for your response. The earlier problem was the intervening
merged rows in-between in the source sheet: Credit MIS and in the
destination
sheet: Asia. I've removed all of the merged rows and basically just want
to
do this:

Copy the range H7:H48 in Credit MIS (it's a fixed range to copy)
Paste special as values into "Asia"'s next available col range,
to the right of the last filled col range,
starting the paste identically in row 7
(eg if last filled col range in Asia is G7:G48, sub to paste it into
H7:H48)

Grateful if you could help with a sub to do the above


  #5   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Sub to copy n paste special discontiguous ranges from 1 sht to

Per, that worked very nicely for my original query !
Many thanks

Max
Reply
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
Special Copy, Paste Special macro usmc-r70 Excel Programming 3 July 2nd 09 08:12 AM
Copying discontiguous ranges to Word Garry[_8_] Excel Programming 0 December 15th 05 02:38 AM
Code for Printing Discontiguous Ranges GoFigure[_20_] Excel Programming 4 December 14th 05 08:58 PM
Dynamic Copy/Paste Special Formulas/Paste Special Values Sharon Perez Excel Programming 3 August 7th 04 09:49 PM
discontiguous ranges in charts Pilgrim Excel Programming 1 July 3rd 04 05:53 PM


All times are GMT +1. The time now is 07:00 AM.

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

About Us

"It's about Microsoft Excel"