Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 154
Default DATA LINKING MACRO !


I have been able to come up with some code for the following senario,
but it needs a fix. Would someone please take a look at my code posted
below the senario help me with it. I am not good at programming, but I
know this is possible.

This is the Senario:
In my Excel Workbook called "Pool.xls" there are many sheets among
which is sheet X . In
sheet X, column A contains the names of all the other sheets in the
workbook, and columns B and D contain data.
I need a macro that will loop through all the other sheets in the
workbook doing the following :

-If the name of any sheet is equal to the name in Column A of sheet X,
then
(1) copy the corresponding data in column B on the same row of sheet X
and paste it as a Link into the range B19:B19 of the sheet whose name we
matched in column A.
and
(2) copy the corresponding data in column D on the same row of sheet X
and paste it as a Link into the range B20:B20 of the sheet whose name we
matched in column A.

(3) If the ranges to be copied do not contain data, then
do nothing

This is the code I have come up with and need help with --

Dim ws As Worksheet
Dim copy1 As Range
Dim copy2 As Range
Dim copy3 As Range

Dim rng1 As Range
Dim rng2 As Range

Set copy1 = Workbooks("Pool.xls").Worksheets("x"). _
Range("A5:A5")

Set copy2 = Workbooks("Pool.xls").Worksheets("x"). _
Range("B5:B5")

Set copy3 = Workbooks("Pool.xls").Worksheets("x"). _
Range("D5:D5")


Set ws = Workbooks("Pool.xls").ActiveSheet

Set rng1 = ws.Range("B19:B19")

Set rng2 = ws.Range("B20:B20")


For Each ws In ActiveWorkbook.Worksheets

If (copy1.Value = ws.Name) Then

Do Until Intersect(copy1, copy1.Parent.UsedRange) Is Nothing

copy2.Copy
ws.Range(rng1.Address).Paste Link:=True

copy3.Copy
ws.Range(rng2.Address).Paste Link:=True

Set copy1 = copy1.Offset(1)
Set copy2 = copy2.Offset(1)
Set copy3 = copy3.Offset(1)
Set rng1 = rng1.Offset(0)
Set rng2 = rng2.Offset(0)

Application.CutCopyMode = False

Loop

End If

Next ws

-Any assistance would be appreciated. I would really need the macro, so
please help!

Thanks.
Jay Dean





*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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
Macro linking to wrong workbook Tim879 Excel Discussion (Misc queries) 2 August 31st 07 03:36 PM
Linking Macro to Button? Jo[_2_] Excel Discussion (Misc queries) 1 August 2nd 07 08:44 PM
Inserting a button into a cell and linking it to a macro Robb W Excel Discussion (Misc queries) 3 May 2nd 06 09:04 PM
Linking a Macro to a Button bman342 Excel Discussion (Misc queries) 3 April 10th 06 03:35 AM
Macro linking vishu Excel Discussion (Misc queries) 2 July 12th 05 01:16 PM


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