Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Move and Link3

I want to change this code so that the same thing that happens in Sheet 2
will also happen in a 3rd worksheet called Sheet 3. Might you be able to
help?

Sub ML()
Dim rw As Long
Dim rngSource As Range
Dim rngDest As Range
Dim rng As Range

Set rngSource = Worksheets("Sheet 1").Range("A4:H200")
Set rngDest = Worksheets("Sheet 2").Range("B4")

With rngSource
Set rngDest = rngDest.Resize(.Rows.Count * 2, .Columns.Count)
End With

For Each rng In rngSource.Rows
rw = rw + 2
rngDest.Rows(rw).Value = rng.Value
Next

Set rngSource = Worksheets("Sheet 1").Range("Ak4:AK200")
rw = -1
For Each rng In rngSource
rw = rw + 2
rngDest(rw, 1).Formula = "=" & rng.Address(external:=True)
Next

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default Move and Link3

2 things would be of help.

The short dirty way is to assign worksheet to a worksheet object like

Set wshDestination = Thisworkbook.Worksheets("Sheet2")

The better way would be to modulate the code meaning the portion of the code
you want to be performed the say way on Sheet 3 as you want on Sheet 2 would
be put into a different procedure.

Example:

Sub ML()
Dim rw As Long, l_lngWorksheetNumber as Long
Dim rngSource As Range
Dim rngDest As Range
Dim rng As Range

Set rngSource = Worksheets("Sheet 1").Range("A4:H200")
With rngSource
For l_lngWorksheetNumber = 2 to Worksheets("Sheet
1").Parent.Worksheets.Count Step 1
Set rngDest =
Worksheets(l_lngWorksheetNumber).Range("B4").Resiz e(.Rows.Count * 2,
..Columns.Count)
Destination rngDest, rngSource
Next l_lngWorksheetNumber
End With
End Sub

Sub Destination(ByVal rngDest as Excel.Worksheet, ByVal rngSource as
Excel.Worksheet)
Dim rng As Excel.Range

Set rngDest = Worksheets("Sheet 2").Range("B4")

With rngSource
Set rngDest = rngDest.Resize(.Rows.Count * 2, .Columns.Count)
End With

For Each rng In rngSource.Rows
rw = rw + 2
rngDest.Rows(rw).Value = rng.Value
Next

Set rngSource = Worksheets("Sheet 1").Range("Ak4:AK200")
rw = -1
For Each rng In rngSource
rw = rw + 2
rngDest(rw, 1).Formula = "=" & rng.Address(external:=True)
Next
End Sub


Now the above code does assume that "Sheet1" is the first worksheet within
the workbook.

Also, in cause you wondered why I used the l_ in front of
lngWorksheetNumber, it's just one of my programming rules that I use to
distinguish rather if it's procedure level ('l_' for a variable declared
within a method, which the l stands for local), module level ('m_' for a
variable declared in the module level declarations with either the keyword
of Dim or Private), or global level ('g_' for a variable declared in the
module level declarations with the keyword of Public).

--
Thanks,

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"MCheru" wrote in message
...
I want to change this code so that the same thing that happens in Sheet 2
will also happen in a 3rd worksheet called Sheet 3. Might you be able to
help?

Sub ML()
Dim rw As Long
Dim rngSource As Range
Dim rngDest As Range
Dim rng As Range

Set rngSource = Worksheets("Sheet 1").Range("A4:H200")
Set rngDest = Worksheets("Sheet 2").Range("B4")

With rngSource
Set rngDest = rngDest.Resize(.Rows.Count * 2, .Columns.Count)
End With

For Each rng In rngSource.Rows
rw = rw + 2
rngDest.Rows(rw).Value = rng.Value
Next

Set rngSource = Worksheets("Sheet 1").Range("Ak4:AK200")
rw = -1
For Each rng In rngSource
rw = rw + 2
rngDest(rw, 1).Formula = "=" & rng.Address(external:=True)
Next

End Sub



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 arrows don't move black box but move the window Thebit Excel Discussion (Misc queries) 1 April 13th 09 02:06 AM
Find value and move to end of data in same row then move values in Diddy Excel Programming 9 March 30th 09 11:24 AM
excel-how to get the spreadsheet to move as I move the scroll tab excel toiler Excel Discussion (Misc queries) 6 November 7th 07 06:07 PM
How do I stop making the spreadsht move when I move up/dwn/lt/rt? Manny Excel Worksheet Functions 4 April 7th 06 10:30 PM
When I move scroll bar in excell the contents do not move with it ramneek Excel Discussion (Misc queries) 2 June 29th 05 07:35 PM


All times are GMT +1. The time now is 12:14 PM.

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"