Copy one value from one cell and past it into another cell with VBA

Tormenta

New Member
Joined
Sep 1, 2022
Messages
2
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
I am trying to find a way of doing the below with VBA code.

I have a list of numbers that goes from cell A1:A9 and I would like to paste the first value in cell I1, then have a loop that looks into the cell value (Cell A2) and past it 4 cells below I1 and so on. The tricky part is that if there is no number it will be replaced with a dash -, so the VBA code should read the - skip it and past the next value. If I have a number in cell A1 the code should copy and paste it in I1 if the next value in cell A2 is a dash - then it should skip it and check the value in cell A3 if its a number then copy and paste it cell I5. Also the range in A1:A9 is dynamic so it can change it can be A1:A100. How can I accomplish the above with VBA?
VBA..PNG
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Welcome to the Board!

Here is one way:
VBA Code:
Sub MyCopyCells()

    Dim lr As Long
    Dim r As Long
    Dim ir As Long
   
    Application.ScreenUpdating = False
   
'   Initialize column I row variable
    ir = 1
   
'   Find last cell in column A with data
    lr = Cells(Rows.Count, "A").End(xlUp).Row
   
'   Populate column I
    For r = 1 To lr
        If Cells(r, "A") <> "-" Then
            Cells(ir, "I").Value = Cells(r, "A").Value
            ir = ir + 5
        End If
    Next r
   
    Application.ScreenUpdating = True
   
    MsgBox "Macro complete!"

End Sub
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,214,954
Messages
6,122,462
Members
449,085
Latest member
ExcelError

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