Pregunta

Simply, the data looks like this:

ID | Value | Test | Score | 
1  | 30    | a    | b     |
1  | 40    | c    | d     |
2  | 30    | d    | a     |
2  | 40    | e    | c     |

... for 130,000 lines. The value is always 30 or 40, i'd like to replace the 40, Test, and Score and put it in the row with 30 to look like this.

ID | Value | Test | Score |    |   |   |
1  | 30    | a    | b     | 40 | c | d |
2  | 30    | d    | a     | 40 | e | c |

I can't seem to wrap my head around the offset-pasting of values. I've tried with Select.Copy,etc -and I have read nothing but bad things about going that route due to performance issues. Any help would be appreciative!

Thanks, Dan

EDIT: Update -- So I've got it to work, but it will only go through 40 rows before I receive an overflow error. I know this is not optimized or at all the best way to do this - but it was the only thing I could do to figure it out. any input GREATLY appreciative.

I found out that there are a few instances where only 1 ID exists, thus I am checking to see if there are two IDs, if so - copy/paste, otherwise continue to the next row.

Sub Macro4()

' Macro4 Macro
Application.ScreenUpdating = False

Range("H6:K6").Select
Application.CutCopyMode = False
Selection.Copy
Range("L5").Select
ActiveSheet.Paste

Dim r As Integer, ID As Integer, validation As Integer
r = 5

While r < 400
Range("V1:X1").Select
Selection.ClearContents
Range("V1").Select
ID = Cells(r, 1).Value
Selection.Value = ID
Range("W1").Select


ActiveCell.FormulaR1C1 = "=countifs(C[-22],RC[-1])"

validation = Selection.Value
If validation > 1 Then
Cells(r + 1, 8).Select
Range(Selection, Cells(r + 1, 11)).Select
Selection.Copy
Cells(r, 12).Select
ActiveSheet.Paste
r = r + 2
End If

If validation = 1 Then
        r = r + 1
End If

Wend
    Application.ScreenUpdating = True

End Sub
¿Fue útil?

Solución 2

I got it to work by changing:

Dim r As Integer, ID As Integer, validation As Integer

to:

Dim r As Integer, ID as Double, validation As Integer

I read somewhere that double holds significantly larger values -- appreciate all the help, regardless!

Otros consejos

Assuming ID is in A1, formulae should do it:

in E2 40
in F2 =C3
in G2 =D3

Copy down to suit (ensure 40 does not autoincrement), Select F:G, Paste Special, Values... over the top, filter to select 40 in ColumnB and delete selected rows.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top