Edit the code for all data

ayman helmy

New Member
Joined
Mar 17, 2021
Messages
16
Office Version
  1. 365
Platform
  1. Windows
I Use the code below to copy S2 from Sheet2 to paste in k15 in sheet1
Then I run another macro as shown in the code I need to edit this code to do the same for all data in column S


Sub Copy()
'
' Copy Macro
'

'
Range("S2").Select
Selection.Copy
Sheets("Sheet1").Select
Range("K15").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Application.Run "Advance.xlsm!svpdf"
Sheets("Sheet2").Select
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
If I understand your requirements correctly regarding the location for where the pasted data should go, this code might get the job done for you:

VBA Code:
Sub CopyAll()
    Dim lastRow As Long
    Dim i As Long
    
    lastRow = Sheets("Sheet12").Range("S" & Rows.Count).End(xlUp).row
    
    For i = 2 To lastRow
        Sheets("Sheet12").Range("S" & i).Copy
        Sheets("Sheet11").Range("K" & i + 13).PasteSpecial Paste:=xlPasteValues
    Next i
    
    Application.CutCopyMode = False
    Application.Run "Advance.xlsm!svpdf"
End Sub
 
Upvote 0
If I understand your requirements correctly regarding the location for where the pasted data should go, this code might get the job done for you:

VBA Code:
Sub CopyAll()
    Dim lastRow As Long
    Dim i As Long
   
    lastRow = Sheets("Sheet12").Range("S" & Rows.Count).End(xlUp).row
   
    For i = 2 To lastRow
        Sheets("Sheet12").Range("S" & i).Copy
        Sheets("Sheet11").Range("K" & i + 13).PasteSpecial Paste:=xlPasteValues
    Next i
   
    Application.CutCopyMode = False
    Application.Run "Advance.xlsm!svpdf"
End Sub
Above code run the macro by copy all then runs it

What i want is copy s2 in sheet2 to K15 in sheet1 then run macro "advance.xlsm!svpdf"
And repeat the process again on S3 to K15 then run the macro
Then for S4 and S5 etc....
 
Upvote 0
Try

VBA Code:
Sub CopyRunMacro()
Dim Lr As Long, T As Long

Lr = Sheets("sheet2").Range("S" & Rows.Count).End(xlUp).Row
For T = 2 To Lr
Sheets("sheet2").Range("S" & T).Copy Sheets("sheet2").Range("K15")
Application.Run "Advance.xlsm!svpdf"
Next T
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,646
Messages
6,120,718
Members
448,986
Latest member
andreguerra

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