Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default ClearContents on 1st sheet from 2nd sheet

Hi

The code below works without selecting the worksheet "Monthly" & copies data
from "Data" across.


Sub Transfer_Data_to_Monthly_Sheet()

Dim wsWig As Worksheet
Dim wsMth As Worksheet
Set wsWig = Workbooks("WESTPAC.xls").Worksheets("Data")
Set wsMth = Workbooks("WESTPAC.xls").Worksheets("Monthly")

wsWig.[O32:P32].Copy
wsMth.Cells(Rows.Count, "B").End(xlUp).Offset(1, 0).PasteSpecial _
Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

Application.Run "'WESTPAC.xls'!Both_1_Month_UP"

End Sub

This macro also works OK. but jumps across to the "Monthly" worksheet

Sub Macro7()
Application.Goto Reference:="TransStatement"
Selection.ClearContents
End Sub

How do I ClearContents of a named range "TransStatement" on the "Monthly"
sheet without selecting the "Monthly" sheet?
Can someone please help, I now just cannot get the code right.

--
Thank you

Regards
Aussie Bob C.
Using Windows XP Home + Office 2003 Pro
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default ClearContents on 1st sheet from 2nd sheet

Hi Robert

Try this

Range("TransStatement").ClearContents

Regards Yngve

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default ClearContents on 1st sheet from 2nd sheet

Thank you Yngve

I "couldn't see the trees for the forest" :-(

My thinking was "Dim this as"- "Set this as" and placing code between a With
??? & End With.

If I may ask another two Questions:

How would you code if the "Monthly" sheet was in;

1. A seperate unopen Workbook?

2. A seperate open Workbook?

--
Thank you

Regards
Aussie Bob C.
Using Windows XP Home + Office 2003 Pro SP2


"Yngve" wrote:

Hi Robert

Try this

Range("TransStatement").ClearContents

Regards Yngve


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default ClearContents on 1st sheet from 2nd sheet

If you do this:

Set wsMth = Workbooks("otherworkbook.xls").Worksheets("Monthly ")

You could change this:
Range("TransStatement").ClearContents
to
wsMth.range("transstatement").clearcontents
(as long as there was a range named transstatement on that worksheet.

And you'll have to open that other workbook, then use the same statements.

dim Wkbk2 as workbook
dim wsMth as worksheet

set wkbk2 = nothing
on error resume next
set wkbk2 = workbooks("otherworkbook.xls")
on error goto 0

if wkbk2 is nothing then
set wkbk2 = workbooks.open(filename:="C:\yourpath\otherworkboo k.xls")
end if

Set wsMth = wkbk2.Worksheets("Monthly")
wsMth.range("transstatement").clearcontents

wkbk2.close savechanges:=true 'if you want



Robert Christie wrote:

Thank you Yngve

I "couldn't see the trees for the forest" :-(

My thinking was "Dim this as"- "Set this as" and placing code between a With
??? & End With.

If I may ask another two Questions:

How would you code if the "Monthly" sheet was in;

1. A seperate unopen Workbook?

2. A seperate open Workbook?

--
Thank you

Regards
Aussie Bob C.
Using Windows XP Home + Office 2003 Pro SP2

"Yngve" wrote:

Hi Robert

Try this

Range("TransStatement").ClearContents

Regards Yngve



--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default ClearContents on 1st sheet from 2nd sheet

Dave

Thak you very much, greatly appreciated indeed

--
Thank you

Regards
Aussie Bob C.
Using Windows XP Home + Office 2003 Pro SP2


"Dave Peterson" wrote:

If you do this:

Set wsMth = Workbooks("otherworkbook.xls").Worksheets("Monthly ")

You could change this:
Range("TransStatement").ClearContents
to
wsMth.range("transstatement").clearcontents
(as long as there was a range named transstatement on that worksheet.

And you'll have to open that other workbook, then use the same statements.

dim Wkbk2 as workbook
dim wsMth as worksheet

set wkbk2 = nothing
on error resume next
set wkbk2 = workbooks("otherworkbook.xls")
on error goto 0

if wkbk2 is nothing then
set wkbk2 = workbooks.open(filename:="C:\yourpath\otherworkboo k.xls")
end if

Set wsMth = wkbk2.Worksheets("Monthly")
wsMth.range("transstatement").clearcontents

wkbk2.close savechanges:=true 'if you want



Robert Christie wrote:

Thank you Yngve

I "couldn't see the trees for the forest" :-(

My thinking was "Dim this as"- "Set this as" and placing code between a With
??? & End With.

If I may ask another two Questions:

How would you code if the "Monthly" sheet was in;

1. A seperate unopen Workbook?

2. A seperate open Workbook?

--
Thank you

Regards
Aussie Bob C.
Using Windows XP Home + Office 2003 Pro SP2

"Yngve" wrote:

Hi Robert

Try this

Range("TransStatement").ClearContents

Regards Yngve



--

Dave Peterson



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
excel sheet bootom half sheet goes behind top part of sheet rob Excel Worksheet Functions 2 January 17th 09 01:28 AM
Duplicate sheet, autonumber sheet, record data on another sheet des-sa[_2_] Excel Worksheet Functions 0 May 8th 08 06:56 PM
wrong positioning of data in sheet after clearcontents() Rea Excel Programming 1 June 21st 05 12:22 PM
relative sheet references ala sheet(-1)!B11 so I can copy a sheet. RonMc5 Excel Discussion (Misc queries) 9 February 3rd 05 12:51 AM
Inserting a row in sheet A should Insert a row in sheet B, removing a row in Sheet A should remove the corresponding row in sheet B Hannes Heckner Excel Programming 1 March 5th 04 09:10 AM


All times are GMT +1. The time now is 03:33 PM.

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"