ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   NEED a MAJOR help with SHEETS copying MACRO (https://www.excelbanter.com/excel-discussion-misc-queries/208076-need-major-help-sheets-copying-macro.html)

bioyyy

NEED a MAJOR help with SHEETS copying MACRO
 
Hello,

I am trying to copy and column J from an odd number (starting from 05) sheet
to even number sheet:

For example:

copy Column J of 05-Test (Sheet name) and paste column J of 06-Test (Sheet
name)

so on for 07-Test to 08-Test, Up to 25-Test to 26-Test.


Thanks

joel

NEED a MAJOR help with SHEETS copying MACRO
 
Sub CopyColJ()

For Each sht In Sheets

If UCase(Right(Trim(sht.Name), 5)) = "-TEST" Then
ShtNum = Val(sht.Name)
'test if sheet number is odd
If ShtNum Mod 2 = 1 Then
NextShtName = Format(ShtNum + 1, "#00") & _
"-Test"
sht.Columns("J").Copy _
Destination:=Sheets(NextShtName).Columns("J")
End If
End If

Next sht


End Sub

"bioyyy" wrote:

Hello,

I am trying to copy and column J from an odd number (starting from 05) sheet
to even number sheet:

For example:

copy Column J of 05-Test (Sheet name) and paste column J of 06-Test (Sheet
name)

so on for 07-Test to 08-Test, Up to 25-Test to 26-Test.


Thanks


Sheeloo[_3_]

NEED a MAJOR help with SHEETS copying MACRO
 
Try the macro
'Note: No error checking
Sub copyToAlternateSheets()
Dim i As Integer
Dim ws As Worksheet
Dim srcName, destName As String

For i = 5 To 13 Step 2
If i < 10 Then
srcName = "0" & i & "-Test"
destName = "0" & (i + 1) & "-Test"
Else
srcName = i & "-Test"
destName = (i + 1) & "-Test"
End If
If i = 9 Then
srcName = "0" & i & "-Test"
destName = (i + 1) & "-Test"
End If
Set ws = Worksheets(srcName)
If (ws.Name < "") Then
Worksheets(srcName).Activate
ActiveSheet.Columns("J:J").Copy
Worksheets(destName).Activate
ActiveSheet.Range("J1").Select
ActiveSheet.Paste
End If
Next i
End Sub


"bioyyy" wrote:

Hello,

I am trying to copy and column J from an odd number (starting from 05) sheet
to even number sheet:

For example:

copy Column J of 05-Test (Sheet name) and paste column J of 06-Test (Sheet
name)

so on for 07-Test to 08-Test, Up to 25-Test to 26-Test.


Thanks


bioyyy

NEED a MAJOR help with SHEETS copying MACRO
 
Joel and Sheelo:

Thanks for your BIG help! But I made one big mistake in my question.

The sheet names are not the same as I wrote Test. Actually, each sheet has
different names (i.e. 05-ABC, 06-Test, 07-adge, 08-iesdf, .....For example).
I hope you can help me to fix it. Thanks again,



"Sheeloo" wrote:

Try the macro
'Note: No error checking
Sub copyToAlternateSheets()
Dim i As Integer
Dim ws As Worksheet
Dim srcName, destName As String

For i = 5 To 13 Step 2
If i < 10 Then
srcName = "0" & i & "-Test"
destName = "0" & (i + 1) & "-Test"
Else
srcName = i & "-Test"
destName = (i + 1) & "-Test"
End If
If i = 9 Then
srcName = "0" & i & "-Test"
destName = (i + 1) & "-Test"
End If
Set ws = Worksheets(srcName)
If (ws.Name < "") Then
Worksheets(srcName).Activate
ActiveSheet.Columns("J:J").Copy
Worksheets(destName).Activate
ActiveSheet.Range("J1").Select
ActiveSheet.Paste
End If
Next i
End Sub


"bioyyy" wrote:

Hello,

I am trying to copy and column J from an odd number (starting from 05) sheet
to even number sheet:

For example:

copy Column J of 05-Test (Sheet name) and paste column J of 06-Test (Sheet
name)

so on for 07-Test to 08-Test, Up to 25-Test to 26-Test.


Thanks


Sheeloo[_3_]

NEED a MAJOR help with SHEETS copying MACRO
 
Try
Sub copyToAlternateSheets()
Dim i As Integer
Dim ws, dest As Worksheet
Dim srcName, destName As String
Dim wksNumber
For Each ws In Worksheets
wksNumber = CInt(Left(ws.Name, 2))
If (wksNumber Mod 2) = 1 Then
srcName = ws.Name
For Each dest In Worksheets
If CInt(Left(dest.Name, 2)) = "0" & (wksNumber + 1) Then
destName = dest.Name
Exit For
End If
Next dest
Worksheets(srcName).Activate
ActiveSheet.Columns("J:J").Copy
Worksheets(destName).Activate
ActiveSheet.Range("J1").Select
ActiveSheet.Paste
End If
Next ws
End Sub

"bioyyy" wrote:

Joel and Sheelo:

Thanks for your BIG help! But I made one big mistake in my question.

The sheet names are not the same as I wrote Test. Actually, each sheet has
different names (i.e. 05-ABC, 06-Test, 07-adge, 08-iesdf, .....For example).
I hope you can help me to fix it. Thanks again,





All times are GMT +1. The time now is 03:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com