Copy data from the previous upper line and paste to current row

Linda Lo

New Member
Joined
May 15, 2023
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
Dear all,

I am a fresh VBA learner. The code written was so straightforward. Please help to point out the following how to rewrite again in order to run it faster.

VBA Code:
Dim i As Integer

    For i = 1 To 10000

   

    

    If Cells(i, 11) > 0 And Cells(i, 1) = "" Then

    Cells(i, 1).Select

    Selection.End(xlUp).Select

    Selection.Copy

    Cells(i, 1).Select

    ActiveSheet.Paste

   

    Else

    End If

    Next i

 

 

    Dim j As Integer

    For j = 1 To 10000

   

    

    If Cells(j, 11) > 0 And Cells(j, 2) = "" Then

    Cells(j, 2).Select

    Selection.End(xlUp).Select

    Selection.Copy

    Cells(j, 2).Select

    ActiveSheet.Paste

   

    Else

    End If

    Next j

 

 

    Dim k As Integer

    For k = 1 To 10000

   

    

    If Cells(k, 11) > 0 And Cells(k, 7) = "" Then

    Cells(k, 7).Select

    Selection.End(xlUp).Select

    Selection.Copy

    Cells(k, 7).Select

    ActiveSheet.Paste

   

    Else

    End If

    Next k

 

 

    Dim m As Integer

    For m = 1 To 10000

   

    

    If Cells(m, 11) > 0 And Cells(m, 8) = "" Then

    Cells(m, 8).Select

    Selection.End(xlUp).Select

    Selection.Copy

    Cells(m, 8).Select

    ActiveSheet.Paste

   

    Else

    End If

    Next m

   

    

    Dim n As Integer

    For n = 1 To 10000

   

    

    If Cells(n, 11) > 0 And Cells(n, 9) = "" Then

    Cells(n, 9).Select

    Selection.End(xlUp).Select

    Selection.Copy

    Cells(n, 9).Select

    ActiveSheet.Paste

   

    Else

    End If

    Next n
By using data of the upper previous row when the current specific's row cell has value. Copy specific cells and paste them to same column current row cells.


I don't know how to write the code to copy the cell from 1 to 9 (without 3 to 6) in the same row from previous upper row and paste 1 to 9 (without 3 to 6) in the current row.

Thank a lot.

Linda Lo
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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