Ну, объект Range
может получить либо Cells
в качестве аргументов, либо String
(подробности здесь ).
Жесткое кодирование диапазона со строковым аргументом будет выглядеть так:
wskpInput_source.Range("G28:L28").Copy _
destination:=wskpInput_target.Range(cell_target)
, но поскольку у вас уже есть переменная, содержащая первую ячейку ("G28") в строке, мынужно только найти последнюю ячейку, вы можете получить ее с помощью Function
, как показано ниже:
Function GetLastCellInRow(sheetName As String, firstCell As String) As String
Sheets(sheetName).Range(firstCell).End(xlToRight).Select
GetLastCellInRow = ActiveCell.Address
End Function
, и вот как вы ее называете
'MySheet is the source sheet, so you need to modify that
cell_source_last = GetLastCellInRow(MySheet.Name, cell_source)
И складывая все вместе:
cell_source = rng.Cells(i, 1)
cell_target = rng.Cells(i, 1).Offset(0, 1)
cell_cellrow = rng.Cells(i, 1).Offset(0, 3)
'MySheet is the source sheet, so you need to modify that
cell_source_last = GetLastCellInRow(MySheet.Name, cell_source)
If cell_cellrow = "Cell" Then 'If cell then copy paste value in that cell
wskpInput_target.Range(cell_target) = wskpInput_source.Range(cell_source).Value
ElseIf cell_cellrow = "Row" Then 'If row then copy and paste the row of cells
wskpInput_source.Range(cell_source & ":" & cell_source_last).Copy _
Destination:=wskpInput_target.Range(cell_target)
End If