Clairexcel
New Member
- Joined
- Mar 23, 2021
- Messages
- 31
- Office Version
- 2016
- 2010
Hello everyone,
I have been working on a new project and so far I managed to create userforms to add, edit, I am pretty satisfied )
However I am stuck with another vba code: I made it loop only into the used range of the source sheet and copy/paste into the destination sheet only the rows that contain the specific ans (the specific id number) that exists in column I in the source sheet.
It works perfectly but I need to make two adjustments:
1. I want this code to copy/paste only specific cells into the destination sheet and not the entire row. For example I want it to find it to find the rows containing the ans number and the copy/paste into the destination sheet only the cells A, B, C, H and P of those rows, not the entire row. So this is the line I should modify nut I do not know how:
xRRg.EntireRow.Copy
It is driving me nuts, but I do not know how to tell him to only copy cells A, B, C ,H and P (for example) in the destination sheet.
2. Every time I run the code, formating of the destination sheet goes lost. It is not a big issue, but I would like for the destination sheet to preserve format I gave it...if possible.
Now the macro command button for this code is in the home page (so not on the destination sheet nor on the source sheet.
Any help would be highly apreciated guys, so thank you in advance.
Here is the vba code I put together
Hope you can help me, thanks
I have been working on a new project and so far I managed to create userforms to add, edit, I am pretty satisfied )
However I am stuck with another vba code: I made it loop only into the used range of the source sheet and copy/paste into the destination sheet only the rows that contain the specific ans (the specific id number) that exists in column I in the source sheet.
It works perfectly but I need to make two adjustments:
1. I want this code to copy/paste only specific cells into the destination sheet and not the entire row. For example I want it to find it to find the rows containing the ans number and the copy/paste into the destination sheet only the cells A, B, C, H and P of those rows, not the entire row. So this is the line I should modify nut I do not know how:
xRRg.EntireRow.Copy
It is driving me nuts, but I do not know how to tell him to only copy cells A, B, C ,H and P (for example) in the destination sheet.
2. Every time I run the code, formating of the destination sheet goes lost. It is not a big issue, but I would like for the destination sheet to preserve format I gave it...if possible.
Now the macro command button for this code is in the home page (so not on the destination sheet nor on the source sheet.
Any help would be highly apreciated guys, so thank you in advance.
Here is the vba code I put together
VBA Code:
Public Sub CopyRows_BOLLA()
Dim xWs As Worksheet
Dim xCWs As Worksheet
Dim xRg As Range
Dim xStrName As String
Dim xRRg As Range
Dim xC As Integer
Dim ans As String
On Error Resume Next
Application.DisplayAlerts = False
xStr = "BOLLA"
ans = "0000"
Set xCWs = ActiveWorkbook.Worksheets.Item(xStr)
If Not xCWs Is Nothing Then
xCWs.Delete
End If
Set xCWs = ActiveWorkbook.Worksheets.Add
xCWs.Name = xStr
ans = InputBox("Bolla")
xC = 3
For Each xWs In ActiveWorkbook.Worksheets
If xWs.Name <> xStr Then
Set xRg = xWs.Range("I:I")
Set xRg = Intersect(xRg, xWs.UsedRange)
For Each xRRg In xRg
If xRRg.Value = ans Then
xRRg.EntireRow.Copy
xCWs.Cells(xC, 1).PasteSpecial xlPasteValuesAndNumberFormats
xC = xC + 1
End If
Next xRRg
End If
Next xWs
Application.DisplayAlerts = True
End Sub
Hope you can help me, thanks
Last edited: