Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50049

Copying Value if other cell value is "ok"

$
0
0
Hi there,

I am currently stuck at some basic vba stuff. I am trying to copy values from column K of sheet 1 to column A in sheet 2, if column A (sheet 1) has the value "ok".

A try to visualize my problem:

Sheet 1 (dots are space)
  • Work 1 | work 2 | Number
  • .."ok"...|...........|.234412
  • .."ok"...|...........|.234416
  • .........|...."ok"...|.234418
where Work 1 = A ; Work 2 = B ; Number = K

After I use the macro, Sheet 2 should look like this
  • Work 1 | work 2
  • .234412|234418|.
  • .234416|...........|
  • ...........|..........|

I am currently using this macro, but it won't work
The list starts at row 16

Code:

Public Sub CopyRows()
    Sheets("AEKOAufstellung").Select
    ' Find the last row of data
    FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
    ' Loop through each row
    For x = 16 To FinalRow Step 1
      ' Decide if to copy based on column K
        ThisValue = Cells(x, 1).Value
        If ThisValue = "ok" Then
            Cells(x, 11).Copy
            Sheets("NeueAEKOs").Select
            NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
            Cells(NextRow, 1).Select
            ActiveSheet.Paste
            Sheets("AEKOAufstellung").Select
        End If
    Next x
    Sheets("NeueAEKOs").Select
End Sub


I hope you can help me with that, I really don't know what to do

Viewing all articles
Browse latest Browse all 50049

Trending Articles