Copy paste loop through columns

Eags123

New Member
Joined
Aug 11, 2018
Messages
2
I am a VBA beginner and I have copied and modified some existing code to suit my purposes, but I'm doing something simple wrong.

What I am trying to achieve is the following: - Loop through Row 1, from Column A to Column Z - If cell of row 1 is greater than 0, Copy Row 1 cell, and paste it in Row 2.

Below is the code I'm using.

Sub CopyData()

Dim LastRow As Long, ws As Worksheet

Set ws = Sheets("Sheet3")

For x = A To Z
If ws.Range(x & "1").Value <> 0 Then
ws.Range(x & "1").Copy
ws.Range(x & "2").PasteSpecial xlPasteValues
End If
Next x

End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Code:
Sub CopyData()
Dim LastRow As Long, ws As Worksheet, x%
Set ws = Sheets("Sheet1")
For x = 1 To 26
    If ws.Cells(1, x) <> 0 Then _
        ws.Cells(2, x) = ws.Cells(1, x).Value
Next x
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

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