Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 440
Default Copy varaible no. of rows to another woorkbook

The following should work but it only copies cell A1 from the SSh (source) to
cell A1 on the DSh (destination).

Sub MoveData()

Dim SSh As Worksheet 'source sheet
Dim DSh As Worksheet 'target sheet
Dim LastRow As Long
Dim CopyRange As String

Set SSh = ActiveWorkbook.ActiveSheet
Set DSh = Workbooks("CMS Register of ClaimsAuto").Worksheets("Summary")

CopyRange = SSh.Range("A2:E" & Rows.count).End(xlUp).Copy

DSh.Range("A" & LastRow + 1).PasteSpecial (xlPasteValues)
End Sub

Where did I go wrong?

--
Traa Dy Liooar

Jock
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Copy varaible no. of rows to another woorkbook

Jock,

Try this

Sub MoveData()

Dim SSh As Worksheet 'source sheet
Dim DSh As Worksheet 'target sheet
Dim LastRow As Long
Dim CopyRange As String
Set SSh = ActiveWorkbook.ActiveSheet
Set DSh = Workbooks("CMS Register of ClaimsAuto.xlsx").Worksheets("Summary")
LastRow = SSh.Cells(Cells.Rows.Count, "E").End(xlUp).Row
SSh.Range("A2:E" & LastRow).Copy
LastRow = DSh.Cells(Cells.Rows.Count, "A").End(xlUp).Row
DSh.Range("A" & LastRow + 1).PasteSpecial (xlPasteValues)
End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Jock" wrote:

The following should work but it only copies cell A1 from the SSh (source) to
cell A1 on the DSh (destination).

Sub MoveData()

Dim SSh As Worksheet 'source sheet
Dim DSh As Worksheet 'target sheet
Dim LastRow As Long
Dim CopyRange As String

Set SSh = ActiveWorkbook.ActiveSheet
Set DSh = Workbooks("CMS Register of ClaimsAuto").Worksheets("Summary")

CopyRange = SSh.Range("A2:E" & Rows.count).End(xlUp).Copy

DSh.Range("A" & LastRow + 1).PasteSpecial (xlPasteValues)
End Sub

Where did I go wrong?

--
Traa Dy Liooar

Jock

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 440
Default Copy varaible no. of rows to another woorkbook

Almost perfect.
This procedure will copy bold text from the source sheet to the destination
sheet. Just prior to that happening, I need all text on the Dest sht from row
4 onwards to be bold = False. How would that be done?
--
Traa Dy Liooar

Jock


"Mike H" wrote:

Jock,

Try this

Sub MoveData()

Dim SSh As Worksheet 'source sheet
Dim DSh As Worksheet 'target sheet
Dim LastRow As Long
Dim CopyRange As String
Set SSh = ActiveWorkbook.ActiveSheet
Set DSh = Workbooks("CMS Register of ClaimsAuto.xlsx").Worksheets("Summary")
LastRow = SSh.Cells(Cells.Rows.Count, "E").End(xlUp).Row
SSh.Range("A2:E" & LastRow).Copy
LastRow = DSh.Cells(Cells.Rows.Count, "A").End(xlUp).Row
DSh.Range("A" & LastRow + 1).PasteSpecial (xlPasteValues)
End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Jock" wrote:

The following should work but it only copies cell A1 from the SSh (source) to
cell A1 on the DSh (destination).

Sub MoveData()

Dim SSh As Worksheet 'source sheet
Dim DSh As Worksheet 'target sheet
Dim LastRow As Long
Dim CopyRange As String

Set SSh = ActiveWorkbook.ActiveSheet
Set DSh = Workbooks("CMS Register of ClaimsAuto").Worksheets("Summary")

CopyRange = SSh.Range("A2:E" & Rows.count).End(xlUp).Copy

DSh.Range("A" & LastRow + 1).PasteSpecial (xlPasteValues)
End Sub

Where did I go wrong?

--
Traa Dy Liooar

Jock

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
Select range from a varaible Excel User[_2_] Excel Programming 5 January 5th 09 03:58 PM
Hyperlink varaible substitution - How To Sledge Bacon Excel Worksheet Functions 10 May 29th 08 06:03 PM
Object varaible or With block variable not set? Rick S. Excel Programming 4 September 26th 07 07:20 PM
assining a varaible to the value in another sheet. shishi Excel Programming 1 August 8th 05 09:40 PM
Use varaible for worsheet name in a formule slm Excel Programming 3 July 19th 05 12:34 PM


All times are GMT +1. The time now is 06:02 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"