|
Anthony's VBA Forum Where the knowledge is shared |
|
|
View previous topic :: View next topic |
Author |
Message |
bgnew
Joined: 18 Nov 2008 Posts: 2
|
Posted: Tue Nov 18, 2008 10:16 pm Post subject: need help: run-time error '1004': Application-defined or... |
|
|
Hi,
I have very little programming experience, but I have to pull together some data from an excel file for my work.
I am trying to select cells based on a particular range from sheet5 and paste them into sheet1 of the same workbook. I am getting the following error: run-time error '1004': Application-defined or object-defined error. Could someone please help me figure out what I'm doing wrong? I'm assuming I need to give the cells a dim, but I'm not sure...
The code is posted below:
Sub SelectBlScores()
'Create a loop that looks for a particular type of score, copy the specified information, and past it on a new sheet
For Each cell In Worksheets("Sheet5").Range("B2:B450 AJ2:AJ450 AK2:AK450 AL2:AL450 AM2:AM450 AV2:AV450 AW2:AW450 AX2:AX450")
If cell.Value = "bl" Or cell.Value < 50 Then
cell.Value.Select
Selection.Copy
Worksheets("Sheet2").PasteSpecial
End If
Next cell
End Sub
I also tried this using Rows as a dim, but I need to select multiple non-consecutive columns, and I'm not sure how to do that:
Sub Select_bl_Scores2()
'Define Dimensions
Dim Row As Long
'Create a loop that looks for a particular type of score, copy the specified information, and past it on a new sheet
For Row = 2 To 414
If Cells(Row, 2).Value = "bl" Or Cells(Row, 2).Value < 50 Then
Cells(Row, 2).Select
Selection.Copy
Worksheets("Sheet2").PasteSpecial
End If
Next Row
End Sub
Thanks to anyone who even attempts to help me! |
|
Back to top |
|
|
LB
Joined: 19 Nov 2008 Posts: 1
|
Posted: Wed Nov 19, 2008 3:32 am Post subject: |
|
|
Upload your files,This will help you better solve the problem |
|
Back to top |
|
|
bgnew
Joined: 18 Nov 2008 Posts: 2
|
Posted: Wed Nov 19, 2008 3:41 am Post subject: |
|
|
Thanks, but I actually figured it out...it's probably not the most programmer friendly method, but it works!
Code:
Sub Select_bl_frq1_Scores()
'Define Dimensions
Dim Row As Long
Dim Column As Long
'Create a loop that looks for a particular type of score, copy the specified information, and past it on a new sheet
'For first loop, only need data from column 2, but not allowed to say "If = one number only" so added column 1 because no data will = bl
For Row = 2 To 58
For Column = 1 To 2
If Cells(Row, Column).Value = "bl" Then
Cells(Row, Column).Select
Selection.Copy
Worksheets("bl").PasteSpecial
End If
Next Column
For Column = 36 To 39
If Cells(Row, Column).Value < 50 Then
Cells(Row, Column).Select
Selection.Copy
Worksheets("bl").PasteSpecial
End If
Next Column
For Column = 48 To 50
If Cells(Row, Column).Value < 50 Then
Cells(Row, Column).Select
Selection.Copy
Worksheets("bl").PasteSpecial
End If
Next Column
Next Row
End Sub |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2002 phpBB Group
|