ToseSenpai
New Member
- Joined
- Apr 18, 2021
- Messages
- 29
- Office Version
- 365
- Platform
- Windows
Hi,
I have this VBA code that i can use for search a specific value (for example "R") in a sheet and then copy the row with the specific value in an other sheet.
How can i copy only a specific range instead the entire row?
".EntireRow.Copy Destination:=destRng"
I need to copy only A-B-C-D-F the specific row, not entire row.
Thank you very much for your help
I have this VBA code that i can use for search a specific value (for example "R") in a sheet and then copy the row with the specific value in an other sheet.
How can i copy only a specific range instead the entire row?
".EntireRow.Copy Destination:=destRng"
I need to copy only A-B-C-D-F the specific row, not entire row.
Thank you very much for your help
VBA Code:
Public Sub SMACROTRRRR()
Dim WB As Workbook
Dim srcSH As Worksheet, destSH As Worksheet
Dim srcRng As Range, destRng As Range
Dim rCell As Range
Dim delRng As Range
Dim iLastRow As Long, jLastRow As Long
Const sStr As String = "R" '<<==== Edit
Set WB = ThisWorkbook
With WB
Set srcSH = .Sheets("MEMO") '<<==== Edit
Set destSH = .Sheets("ARCHIVIO RETTIFICHE") '<<==== Edit
End With
With srcSH
iLastRow = LastRow(srcSH, .Columns("A:A"))
Set srcRng = .Range("A1:A" & iLastRow)
End With
With destSH
jLastRow = LastRow(destSH, .Columns("A:A"))
Set destRng = .Range("A" & jLastRow + 1)
End With
On Error GoTo XIT
Application.ScreenUpdating = False
For Each rCell In srcRng.Columns(24).Cells
With rCell
If UCase(.Value) = UCase(sStr) Then
If delRng Is Nothing Then
Set delRng = rCell
Else
Set delRng = Union(rCell, delRng)
End If
End If
End With
Next rCell
If Not delRng Is Nothing Then
With delRng
.EntireRow.Copy Destination:=destRng
End With
Else
'nothing found, do nothing
End If
End Sub