If cells contain the same numbers How to Copy the entire row

punnipah

Board Regular
Joined
Nov 3, 2021
Messages
134
Office Version
  1. 2019
Platform
  1. Windows
If cells contain the same numbers Copy the entire row value and paste it in the next column.

How to Type VBA Code

Ex. If Columns "G" is the Same Number and then Copy Word "CI" the entire row and Word "UOB" Copy the entire row.

Looping

1661753776089.png
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi,
One question.
If column G has the same #, Copy the entire row or Copy BP and BQ only?
 
Upvote 0
Hi,
Here is a basic sample. Depending on the data count, this sample access to the cell in a loop, you might feel slow. Anyway, give it a try then.

VBA Code:
Sub Sample1()
    Dim i As Long, p As String
    Application.ScreenUpdating = False
    For i = 2 To Cells(Rows.Count, "G").End(xlUp).Row
        If Cells(i, "G").Value = p Then
            Cells(i, "BP").Resize(, 2).Value = Cells(i - 1, "BP").Resize(, 2).Value
        End If
        p = Cells(i, "G").Value
    Next
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
it's awesome Thank you Very much.
Hi,
Here is a basic sample. Depending on the data count, this sample access to the cell in a loop, you might feel slow. Anyway, give it a try then.

VBA Code:
Sub Sample1()
    Dim i As Long, p As String
    Application.ScreenUpdating = False
    For i = 2 To Cells(Rows.Count, "G").End(xlUp).Row
        If Cells(i, "G").Value = p Then
            Cells(i, "BP").Resize(, 2).Value = Cells(i - 1, "BP").Resize(, 2).Value
        End If
        p = Cells(i, "G").Value
    Next
    Application.ScreenUpdating = True
End Sub[/CODE
[/QUOTE]
 
Upvote 0
Hi there! Try this one.

VBA Code:
Sub Sample2()
    Dim i As Long, p As String
    Application.ScreenUpdating = False
    For i = 2 To Cells(Rows.Count, "G").End(xlUp).Row
        If Cells(i, "G").Value = p Then
            If Cells(i, "BP").Value = "" Then
                Cells(i, "BP").Resize(, 2).Value = Cells(i - 1, "BP").Resize(, 2).Value
            End If
        End If
        p = Cells(i, "G").Value
    Next
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Hi there! Try this one.

VBA Code:
Sub Sample2()
    Dim i As Long, p As String
    Application.ScreenUpdating = False
    For i = 2 To Cells(Rows.Count, "G").End(xlUp).Row
        If Cells(i, "G").Value = p Then
            If Cells(i, "BP").Value = "" Then
                Cells(i, "BP").Resize(, 2).Value = Cells(i - 1, "BP").Resize(, 2).Value
            End If
        End If
        p = Cells(i, "G").Value
    Next
    Application.ScreenUpdating = True
End Sub
Thnk you Verymuch
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top