Combine multiple macros into one [VBA]

Martin_H

Board Regular
Joined
Aug 26, 2020
Messages
190
Office Version
  1. 365
Platform
  1. Windows
Hi,

would it be possible to combine all the code below into a one macro?

Thank you for help.

VBA Code:
Sub Copy_One()
Dim WS As Worksheet
Dim r As Range
Dim i As Long
i = 1
For Each WS In ActiveWorkbook.Worksheets
If WS.Name <> "SAP" And WS.Name <> "PLAN" And WS.Name <> "SUM" And WS.Name <> "TACHO" Then
Worksheets("TACHO").Range("J" & i & ":J" & i).Value = WS.Range("T128").Value
i = i + 1
End If
Next WS
End Sub


Sub Copy_Two()
Dim WS As Worksheet
Dim r As Range
Dim i As Long
i = 1
For Each WS In ActiveWorkbook.Worksheets
If WS.Name <> "SAP" And WS.Name <> "PLAN" And WS.Name <> "SUM" And WS.Name <> "TACHO" Then
Worksheets("TACHO").Range("M" & i & ":M" & i).Value = WS.Range("AO128").Value
i = i + 1
End If
Next WS
End Sub


Sub Copy_Three()
Dim WS As Worksheet
Dim r As Range
Dim i As Long
i = 1
For Each WS In ActiveWorkbook.Worksheets
If WS.Name <> "SAP" And WS.Name <> "PLAN" And WS.Name <> "SUM" And WS.Name <> "TACHO" Then
Worksheets("TACHO").Range("N" & i & ":N" & i).Value = WS.Range("AZ128").Value
i = i + 1
End If
Next WS
End Sub


Sub Copy_Four()
Dim WS As Worksheet
Dim r As Range
Dim i As Long
i = 1
For Each WS In ActiveWorkbook.Worksheets
If WS.Name <> "SAP" And WS.Name <> "PLAN" And WS.Name <> "SUM" And WS.Name <> "TACHO" Then
Worksheets("TACHO").Range("K" & i & ":K" & i).Value = WS.Range("AL128").Value
i = i + 1
End If
Next WS
End Sub


Sub Copy_Five()
Dim WS As Worksheet
Dim r As Range
Dim i As Long
i = 1
For Each WS In ActiveWorkbook.Worksheets
If WS.Name <> "SAP" And WS.Name <> "PLAN" And WS.Name <> "SUM" And WS.Name <> "TACHO" Then
Worksheets("TACHO").Range("i" & i & ":i" & i).Value = WS.Range("B2").Value
i = i + 1
End If
Next WS
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
You can do that like
VBA Code:
Sub MartinH()
   Dim WS As Worksheet
   Dim i As Long
   i = 1
   For Each WS In ActiveWorkbook.Worksheets
      If WS.Name <> "SAP" And WS.Name <> "PLAN" And WS.Name <> "SUM" And WS.Name <> "TACHO" Then
         With Worksheets("TACHO")
            .Range("J" & i).Value = WS.Range("T128").Value
            .Range("M" & i).Value = WS.Range("AO128").Value
            .Range("N" & i).Value = WS.Range("AZ128").Value
         End With
         i = i + 1
      End If
   Next WS
End Sub
 
Upvote 0
Solution
Much much better (y)

Thanks for the lightning fast response Fluff!
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,367
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top