Giovanni03
New Member
- Joined
- May 23, 2023
- Messages
- 33
- Office Version
- 365
- 2021
- Platform
- Windows
Hello Guys!
I have a code that works great for what I'm looking to do however there is just one portion of the code that I'm wondering if what I'm trying to achieve could be implemented. Basically what the code does is that it allows me to select any number of rows then when I run the macro, it paste those rows into the sheet I need it in and then deletes it from the sheet that it was copied from. Again it works great but when the copied data gets pasted onto the new sheet it paste over a section that I would like to keep (basically a notes section that I include on the the pasted sheet that starts in column L)
Is is possible to have only columns A-K paste and not the entire row which has a ton of blanks after column k.
I have a code that works great for what I'm looking to do however there is just one portion of the code that I'm wondering if what I'm trying to achieve could be implemented. Basically what the code does is that it allows me to select any number of rows then when I run the macro, it paste those rows into the sheet I need it in and then deletes it from the sheet that it was copied from. Again it works great but when the copied data gets pasted onto the new sheet it paste over a section that I would like to keep (basically a notes section that I include on the the pasted sheet that starts in column L)
Is is possible to have only columns A-K paste and not the entire row which has a ton of blanks after column k.
VBA Code:
Sub CopyToSIS()
'Declarations.
Dim RngSource As Range
Dim RngDestination As Range
Dim RngArea As Range
Dim RngCell As Range
Dim RngChop As Range
Dim DblBottomRow As Double
Dim DblTopRow As Double
Dim DblRow As Double
'Settings.
Set RngSource = Selection
Set RngDestination = Sheets("S.I.S").Range("A1").End(xlDown)
'Checking if RngDestination is empty, which means its not the last cell of the list.
If Excel.WorksheetFunction.CountBlank(RngDestination) = RngDestination.Cells.Count Then
'Setting RngDestination.
Set RngDestination = RngDestination.End(xlUp).Offset(1, 0)
Else
'Setting RngDestination.
Set RngDestination = RngDestination.Offset(1, 0)
End If
'Covering each area of RngSource.
For Each RngArea In RngSource.Areas
'Covering each cell of RngArea.
For Each RngCell In RngArea.Cells
'Checking if RngChop is nothing.
If RngChop Is Nothing Then
'Setting RngChop.
Set RngChop = RngCell.EntireRow
Else
'Setting RngChop.
Set RngChop = Union(RngChop, RngCell.EntireRow)
End If
Next
Next
'Covering each row of RngChop.
For Each RngArea In RngChop.Rows
'Copying the row.
RngArea.copy RngDestination
'Setting RngDestination for the next row.
Set RngDestination = RngDestination.Offset(1, 0)
Next
'Deleting RngChop.
RngChop.Delete
End Sub