Loop Functionality

excel_userss

New Member
Joined
Jun 4, 2019
Messages
11
Hi All
I would like to create a macro where i can paste Columns of Option, Strike and Expiry in respective sheets on the left. I have written a macro. please advice the necessary changes
Sheet1Option StrikeExpiry
NIkitc1120027-Jun-19
sandeepP1130027-Jun-19
Shraddhac1140027-Jun-19
NAyanC1150027-Jun-19
sansbinP1160027-Jun-19

<colgroup><col width="64" span="4" style="width:48pt"> </colgroup><tbody>
</tbody>

Sub Macro1()'Sub SearchSheetName()
Dim xName As String
For m = 2 To Range("g1")
xName = Worksheets("sheet1").Range("A" & m)
Range(("B" & m), ("D" & m)).Copy
Worksheets(xName).Select
Range("A2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).PasteSpecial

'Selection.Value = Worksheets("sheet1").Range(("B" & m), ("c" & m))
Next m
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Like...

Code:
Sub Macro1() 'Sub SearchSheetName()
Dim xName As String
For m = 2 To 6
xName = Worksheets("Sheet1").Range("A" & m)
Range(("B" & m), ("D" & m)).Copy
Worksheets(xName).Select
[COLOR=#0000ff]ActiveSheet.[/COLOR]Range("A2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).PasteSpecial
Next m
[COLOR=#0000ff]Worksheets("Sheet1").Select[/COLOR]
[COLOR=#0000ff]Application.CutCopyMode = False[/COLOR]
End Sub

Or preferably avoid copy paste and all the associated selections......

Code:
Sub Macro2() 'Sub SearchSheetName()
Dim xName As String
On Error GoTo Quit
For m = 2 To 6
xName = Worksheets("Sheet1").Range("A" & m)
With Worksheets(xName)


NextRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
.Range("A" & NextRow & ":C" & NextRow).Value = Sheets("Sheet1").Range("B" & m & ":D" & m).Value
End With
Next m
Quit:
End Sub

Hope that helps but please do not make duplicate posts.
 
Upvote 0
Like...

Code:
Sub Macro1() 'Sub SearchSheetName()
Dim xName As String
For m = 2 To 6
xName = Worksheets("Sheet1").Range("A" & m)
Range(("B" & m), ("D" & m)).Copy
Worksheets(xName).Select
[COLOR=#0000ff]ActiveSheet.[/COLOR]Range("A2").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).PasteSpecial
Next m
[COLOR=#0000ff]Worksheets("Sheet1").Select[/COLOR]
[COLOR=#0000ff]Application.CutCopyMode = False[/COLOR]
End Sub

Or preferably avoid copy paste and all the associated selections......

Code:
Sub Macro2() 'Sub SearchSheetName()
Dim xName As String
On Error GoTo Quit
For m = 2 To 6
xName = Worksheets("Sheet1").Range("A" & m)
With Worksheets(xName)


NextRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
.Range("A" & NextRow & ":C" & NextRow).Value = Sheets("Sheet1").Range("B" & m & ":D" & m).Value
End With
Next m
Quit:
End Sub

Hope that helps but please do not make duplicate posts.
The macro worked
Thanks a lot
 
Upvote 0

Forum statistics

Threads
1,215,790
Messages
6,126,926
Members
449,349
Latest member
Omer Lutfu Neziroglu

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