You can create your own procedures to do just about anything you can imagine. You're code can be simplified considerably.
First, we will define a source worksheet and a destination worksheet. We do this to make our code easier to read, interpret, and maintain (there will now only be ONE place where you need to fuss with this messy concatenation: Worksheets(stockcode & "_Stock ratio_" & marketcode)
.
Dim srcSheet as Worksheet
Dim destSheet as Worksheet
Set srcSheet = Worksheets(stockcode & "_IS_" & marketcode)
Set destSheet = Worksheets(stockcode & "_Stock ratio_" & marketcode)
Now we can just use a Value
assignment statement, since you only are concerned with pasting values, you can simply do this:
destSheet.Range("D3").Value = srcSheet.Range("B2").Value
destSheet.Range("D4").Value = srcSheet.Range("B3").Value
destSheet.Range("D5").Value = srcSheet.Range("B15").Value
This entirely avoids the Copy
and Paste/PasteSpecial
methods, and should be faster, too.
You could create a macro that puts this all together and gets a little fancier, it ultimately depends on your use case and how you want to input data or whether that is even necessary (often it is not, as there are logical rules that determine the relationship between sheets, which can be constructed in to code/syntax, etc.)
If you are looking to simply input the information, you can use an Application.InputBox
, here's a simple example:
Sub TransferValues()
Dim src as Range
Dim dest as Range
Set src = Application.InputBox("Source?", Type:=8)
Set dest = Application.InputBox("Destination?", Type:=8)
dest.Value = src.Value
End Sub
Of course, this is not really much faster (if any) than doing copy/paste manually, but it serves to illustrate the concept you may be able to implement.