Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Passing Worksheet Names as Variables


Hi,

I've created a simple macro that accesses a .txt file, copies a range
or data, opens a new document and pastes the data.

I need to increase the functionality of this Macro as follows:

One of the copied cells in the first document contains a value that
needs to be stored into a variable (the value is always in the same
cell so this reference can be hardcoded).

When the new workbook is opened I need to retrieve the value above and
compare it to the worksheet names, once the relevant worksheet has been
found I need to open the worksheet and paste the information into the
appropriate cells.

I'm sure this can be done and am half way to doing it but can't seem to
get the syntax right. If anyone can give me some pointers I'd be very
appreciative. If at all possible could you provide comments for each
step so I can see the processes involved for future reference.
Many thanks
Dave


--
francd1
------------------------------------------------------------------------
francd1's Profile: http://www.excelforum.com/member.php...o&userid=24703
View this thread: http://www.excelforum.com/showthread...hreadid=382715

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Passing Worksheet Names as Variables

Something along the lines of (not tested)

With Activeworkbook 'this will be the newly opened text file
.Range("H1:M10").Copy
Destination:=myWb.Worksheets(.Range("A1").Value).R ange("H1")
End With

This is guessing a bit at what you do in detailed, but it is taking the
value in A1 from the newly opened text file and passing that as the
worksheet name of a workbook object called myWb.

--
HTH

Bob Phillips

"francd1" wrote in
message ...

Hi,

I've created a simple macro that accesses a .txt file, copies a range
or data, opens a new document and pastes the data.

I need to increase the functionality of this Macro as follows:

One of the copied cells in the first document contains a value that
needs to be stored into a variable (the value is always in the same
cell so this reference can be hardcoded).

When the new workbook is opened I need to retrieve the value above and
compare it to the worksheet names, once the relevant worksheet has been
found I need to open the worksheet and paste the information into the
appropriate cells.

I'm sure this can be done and am half way to doing it but can't seem to
get the syntax right. If anyone can give me some pointers I'd be very
appreciative. If at all possible could you provide comments for each
step so I can see the processes involved for future reference.
Many thanks
Dave


--
francd1
------------------------------------------------------------------------
francd1's Profile:

http://www.excelforum.com/member.php...o&userid=24703
View this thread: http://www.excelforum.com/showthread...hreadid=382715



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Passing Worksheet Names as Variables


Thanks for the reply, it looks like it's exactly what I'm after but I
don't seem to be able to get it to work.
It appears the debugger objects to me using the Destination statment
without an expression after it, I have tried the following (apologies
if the parenthesis are in the wrong place but I've tried pretty much
every derivation and can't get it to work)

With Activeworkbook
..Range("C1:D4").Copy
Destination:=Workbooks"Trend
Analysis.xls".Range("A1").Value).Range("C1)
End With

I get a different error depending on whether Destination is on the same
line as the .Copy statment or on a seperate line.

Further to the above it would be handy to have a button in "Trend
Analysis.xls" that when pressed displays a user entry box that allows
the user to enter the name of the .txt file to open. The macro should
then open the .txt file and execute the above section.


--
francd1
------------------------------------------------------------------------
francd1's Profile: http://www.excelforum.com/member.php...o&userid=24703
View this thread: http://www.excelforum.com/showthread...hreadid=382715

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Passing Worksheet Names as Variables

On the basis that it is a text file and will only have 1 worksheet

Set myWb = Workbooks("Book2")
With ActiveWorkbook 'this will be the newly opened text file
.Worksheets(1).Range("H1:M10").Copy _
myWb.Worksheets(.Worksheets(1).Range("A1").Value). Range("H1")
End With


--
HTH

Bob Phillips

"francd1" wrote in
message ...

Thanks for the reply, it looks like it's exactly what I'm after but I
don't seem to be able to get it to work.
It appears the debugger objects to me using the Destination statment
without an expression after it, I have tried the following (apologies
if the parenthesis are in the wrong place but I've tried pretty much
every derivation and can't get it to work)

With Activeworkbook
Range("C1:D4").Copy
Destination:=Workbooks"Trend
Analysis.xls".Range("A1").Value).Range("C1)
End With

I get a different error depending on whether Destination is on the same
line as the .Copy statment or on a seperate line.

Further to the above it would be handy to have a button in "Trend
Analysis.xls" that when pressed displays a user entry box that allows
the user to enter the name of the .txt file to open. The macro should
then open the .txt file and execute the above section.


--
francd1
------------------------------------------------------------------------
francd1's Profile:

http://www.excelforum.com/member.php...o&userid=24703
View this thread: http://www.excelforum.com/showthread...hreadid=382715



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
Passing Variables Jeff Excel Discussion (Misc queries) 1 November 4th 05 06:46 PM
Passing Variables Paula[_3_] Excel Programming 1 August 23rd 04 06:55 PM
Passing Variables Tom Ogilvy Excel Programming 0 July 23rd 04 04:19 PM
Passing listindex to worksheet names David Adamson[_3_] Excel Programming 4 June 4th 04 01:32 AM
Passing Variables Royce[_2_] Excel Programming 1 November 20th 03 02:16 PM


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