Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Loop to tidy up my code?

Hi folks,

I've got a bit of code (see below) that looks up sheet "manacs figures" in
workbook A, copies a range, finds sheet X in workbook B and pastes the
values. It then goes back to the same sheet in workbook A and copies another
range (usually column next to it etc) and then pastes to sheet Y in workbook
B.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Loop to tidy up my code?

Forgot to paste the code in ... doh!! ..... see below for code.

I've cut out some of the copy/paste lines to save space but i've left enough
so you can get an idea of what i'm doing

Regards,

Craig

Sub test()

Application.ScreenUpdating = False

Dim wbs As Workbook
Dim wbt As Workbook
Dim tref As String

Set wbs = Workbooks("ManAcs Import.xls")
Set wbt = Workbooks("ManAcs Master.xls")

tref = "AJ"

wbs.Sheets("ManAcs Figures").Range("E4:E330").Copy
wbt.Sheets("ABFI").Range(tref & "115").PasteSpecial Paste:=xlPasteValues
wbs.Sheets("ManAcs Figures").Range("F4:F330").Copy
wbt.Sheets("ABOP").Range(tref & "115").PasteSpecial Paste:=xlPasteValues
wbs.Sheets("ManAcs Figures").Range("G4:G330").Copy
wbt.Sheets("ABTE").Range(tref & "115").PasteSpecial Paste:=xlPasteValues
wbs.Sheets("ManAcs Figures").Range("H4:H330").Copy
wbt.Sheets("ABNN").Range(tref & "115").PasteSpecial Paste:=xlPasteValues

wbs.Sheets("ManAcs Figures").Range("J4:J330").Copy
wbt.Sheets("EDCC").Range(tref & "115").PasteSpecial Paste:=xlPasteValues
wbs.Sheets("ManAcs Figures").Range("K4:K330").Copy
wbt.Sheets("EDCO").Range(tref & "115").PasteSpecial Paste:=xlPasteValues
wbs.Sheets("ManAcs Figures").Range("L4:L330").Copy
wbt.Sheets("EDFI").Range(tref & "115").PasteSpecial Paste:=xlPasteValues



Application.CutCopyMode = False


Application.ScreenUpdating = True

End Sub









"Craig Handley" wrote:

Hi folks,

I've got a bit of code (see below) that looks up sheet "manacs figures" in
workbook A, copies a range, finds sheet X in workbook B and pastes the
values. It then goes back to the same sheet in workbook A and copies another
range (usually column next to it etc) and then pastes to sheet Y in workbook
B.

The rows being copied each time are constant (rows 4 to 330).

The paste destination is always row 115 (i change the column each month by
changing the column ref near the start of the code)

The value in row 2 of each column in my source workbook is the name of the
sheet in the destination sheet. i.e. E2 = "ABFI" ... i want to copy rows from
E4:E330 to AJ115 in sheet "ABFI".

As you can see i've got the long version of the code working where i specify
each column to copy from and which sheet to post to but i'm sure there must
be a way to shorten this using some form of loop or do while command and also
use the data to identify the destination sheet.

Hopefully all that makes sense and thanks in advance for any help/pointers
you can give.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Loop to tidy up my code?

It would be nicer if you had column i

Sub test()

Application.ScreenUpdating = False

Dim wbs As Workbook
Dim wbt As Workbook
Dim tref As String
Destinations = Array("ABFI", "ABOP", "ABTE", "ABNN", "", "EDCC", "EDCO",
"EDFI")

Set wbs = Workbooks("ManAcs Import.xls")
Set wbt = Workbooks("ManAcs Master.xls")

tref = "AJ"
For i = 0 To UBound(Destinations)
If i < 4 Then 'skip column i

wbs.Sheets("ManAcs Figures").Range("E4:E330").Offset(0, i).Copy
wbt.Sheets(Destinations(i)).Range(tref & "115").PasteSpecial
Paste:=xlPasteValues
End If
Next i

Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub


"Craig Handley" wrote:

Forgot to paste the code in ... doh!! ..... see below for code.

I've cut out some of the copy/paste lines to save space but i've left enough
so you can get an idea of what i'm doing

Regards,

Craig

Sub test()

Application.ScreenUpdating = False

Dim wbs As Workbook
Dim wbt As Workbook
Dim tref As String

Set wbs = Workbooks("ManAcs Import.xls")
Set wbt = Workbooks("ManAcs Master.xls")

tref = "AJ"

wbs.Sheets("ManAcs Figures").Range("E4:E330").Copy
wbt.Sheets("ABFI").Range(tref & "115").PasteSpecial Paste:=xlPasteValues
wbs.Sheets("ManAcs Figures").Range("F4:F330").Copy
wbt.Sheets("ABOP").Range(tref & "115").PasteSpecial Paste:=xlPasteValues
wbs.Sheets("ManAcs Figures").Range("G4:G330").Copy
wbt.Sheets("ABTE").Range(tref & "115").PasteSpecial Paste:=xlPasteValues
wbs.Sheets("ManAcs Figures").Range("H4:H330").Copy
wbt.Sheets("ABNN").Range(tref & "115").PasteSpecial Paste:=xlPasteValues

wbs.Sheets("ManAcs Figures").Range("J4:J330").Copy
wbt.Sheets("EDCC").Range(tref & "115").PasteSpecial Paste:=xlPasteValues
wbs.Sheets("ManAcs Figures").Range("K4:K330").Copy
wbt.Sheets("EDCO").Range(tref & "115").PasteSpecial Paste:=xlPasteValues
wbs.Sheets("ManAcs Figures").Range("L4:L330").Copy
wbt.Sheets("EDFI").Range(tref & "115").PasteSpecial Paste:=xlPasteValues



Application.CutCopyMode = False


Application.ScreenUpdating = True

End Sub









"Craig Handley" wrote:

Hi folks,

I've got a bit of code (see below) that looks up sheet "manacs figures" in
workbook A, copies a range, finds sheet X in workbook B and pastes the
values. It then goes back to the same sheet in workbook A and copies another
range (usually column next to it etc) and then pastes to sheet Y in workbook
B.

The rows being copied each time are constant (rows 4 to 330).

The paste destination is always row 115 (i change the column each month by
changing the column ref near the start of the code)

The value in row 2 of each column in my source workbook is the name of the
sheet in the destination sheet. i.e. E2 = "ABFI" ... i want to copy rows from
E4:E330 to AJ115 in sheet "ABFI".

As you can see i've got the long version of the code working where i specify
each column to copy from and which sheet to post to but i'm sure there must
be a way to shorten this using some form of loop or do while command and also
use the data to identify the destination sheet.

Hopefully all that makes sense and thanks in advance for any help/pointers
you can give.

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
Tidy up multiple find and replace code PSM[_10_] Excel Worksheet Functions 2 April 6th 09 02:00 PM
Can anyone help me tidy up? drucey[_34_] Excel Programming 2 May 5th 06 07:58 PM
Goto misused: help to tidy Code davidm Excel Programming 3 December 20th 05 04:36 AM
smart & tidy code for many checkBox_Change() Fendic[_16_] Excel Programming 3 August 14th 05 02:52 PM
Tidy Up Pete Excel Discussion (Misc queries) 4 May 9th 05 05:09 PM


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