VBABEGINER
Well-known Member
- Joined
- Jun 15, 2011
- Messages
- 1,284
- Office Version
- 365
- Platform
- Windows
Code:
Do Until lx = 12
Loop
how do i mention lx is the column to increment..??
Do Until lx = 12
Loop
Do Until lx = 12
...
lx = lx + 1
Loop
'current lx = 8 i.e. Col H
lx = 8
Cells(2, lx).Select
Do Until lx = 12
x = Sheets.Count
For Shx = 1 To x
j = Range("F" & Rows.Count).End(xlUp).Row
'Here lx = 8
Range(Cells(2, lx), Cells(j, lx)).Select
Selection.Copy
Worksheets("Combine").Select
k = Range("F" & Rows.Count).End(xlUp).Row
Cells(k + 1, lx).Select
ActiveSheet.Paste
Application.CutCopyMode = False
'go to next sheet here..
Next
'do not increament loop..
lx = lx + 1
Loop
Sub fnCombine()
Dim i As Long, j As Long, LC As Integer
Dim ws As Worksheet
Dim x As Integer, z As Integer
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Sheets.Add(After:=Sheets(Sheets.Count)).Name = "Combine"
'1st part
For Each ws In ThisWorkbook.Sheets
If ws.Name = "Combine" Then
Else
ws.Activate
i = Range("F" & Rows.Count).End(xlUp).Row
LC = Cells(1, Columns.Count).End(xlToLeft).Column
If ws.Index = 1 Then
Range("A1:G" & i).Select
Selection.Copy
Worksheets("Combine").Select
Range("A1").Select
ActiveSheet.Paste
Else
Range("A2:G" & i).Select
Selection.Copy
Worksheets("Combine").Select
j = Range("F" & Rows.Count).End(xlUp).Row
Range("A" & j + 1).Select
ActiveSheet.Paste
Application.CutCopyMode = False
End If
End If
Next
'/1st part
'2nd part
'current lx = 8 i.e. Col H
lx = 8
Cells(2, lx).Select
Do Until lx = 12
x = Sheets.Count
For Shx = 1 To x
j = Range("F" & Rows.Count).End(xlUp).Row
'Here lx = 8
Range(Cells(2, lx), Cells(j, lx)).Select
Selection.Copy
Worksheets("Combine").Select
k = Range("F" & Rows.Count).End(xlUp).Row
Cells(k + 1, lx).Select
ActiveSheet.Paste
Application.CutCopyMode = False
'go to next sheet here..
Next
'do not increament loop..
lx = lx + 1
Loop
'/2nd part
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
[TABLE="width: 1191"]
<tbody>[TR]
[TD="class: xl65, width: 100"]Sr. No.[/TD]
[TD="class: xl65, width: 143"]Data Responsibilty[/TD]
[TD="class: xl65, width: 97"]Source[/TD]
[TD="class: xl65, width: 111"]Metric Type[/TD]
[TD="class: xl65, width: 126"]Metric Name[/TD]
[TD="class: xl65, width: 101"]BU[/TD]
[TD="class: xl65, width: 77"]Jan '18[/TD]
[TD="class: xl65, width: 77"]Feb '18[/TD]
[TD="class: xl65, width: 77"]Mar '18[/TD]
[TD="class: xl65, width: 77"]Apr '18[/TD]
[TD="class: xl65, width: 77"]YTD 2018[/TD]
[TD="class: xl65, width: 128"]Comments, If any.[/TD]
[/TR]
</tbody>[/TABLE]
Sheet1 data Jan 18
Sheet2 data Jan 18
Sheet3 data Jan 18
Sheet4 data Jan 18
Sheet5 data Jan 18
Sheet6 data Jan 18
Sheet7 data Jan 18
Sheet1 data Feb 18
Sheet2 data Feb 18
Sheet3 data Feb 18
Sheet4 data Feb 18
.
.
.
and so on...
Sub Test1()
Dim x As Long
Dim Shx As Long
x = Sheets.Count
For Shx = 1 To x
MsgBox "Shx = " & Shx & vbCrLf & _
"Performing code on sheet: " & ActiveSheet.Name
Next Shx
End Sub
Sub Test2()
Dim x As Long
Dim Shx As Long
x = Sheets.Count
For Shx = 1 To x
[COLOR=#ff0000] Sheets(Shx).Activate[/COLOR]
MsgBox "Shx = " & Shx & vbCrLf & _
"Performing code on sheet: " & ActiveSheet.Name
Next Shx
End Sub
Range("A1")
Sheets(Shx).Range("A1")