I need to be able to write a copy subroutine that will read in the input worksheet name and the input cells, and copy this data to a specific output sheet and output cells. This subroutine must be modularized because it will be used in mulitiple worksheets.It will only copy the data from input sheets to output sheets. Here is one I have written but it doesn't work.
Public Sub Copy_Input_Data_To_Output_Data( _
ByVal pv_str_input_worksheet_name As String, _
ByVal pv_str_output_worksheet_name As String, _
ByVal pv_str_input_cell_range As String, _
ByVal pv_str_output_cell_range As String, _
ByRef pr_str_error_message As String)
Worksheets(pv_str_input_worksheet_name).Range(pv_str_input_cell_range).Value = _
Worksheets(pv_str_output_worksheet_name).Range(pv_str_output_cell_range).Value
End Sub
Here is the code of that subroutine being applied to a input sheet.
Call Copy_Input_Data_To_Output_Data( _
pv_str_in… _
pv_str_output_worksheet_name:="Sheet2", _
pv_str_input_cell_range:="B13:B17", _
pv_str_output_cell_range:=""B17,B20,B34,B18,B21", _
pr_str_error_message:=str_error_message)
As you can see this code is copying ranges of input cells and the data goes to specific output cells in another sheet. Please help I would greatly appericate it! :)
Try the
Copy
method of theRange
object. Something like the following, provided your ranges are OK - they are copied toRange
objects for readability:If you change the statement calling the sub it will work - but maybe not as intended:
Try this code out. It will work pasting a contiguous range to / from a non-contiguous range and vice versa. You could probably enhance it to even be smart enough to detect if it's two same-sized contiguous ranges, so it wouldn't loop unnecessarily.
I've also reworded the code to simplify readability.