Anthony's VBA Forum Index Anthony's VBA Forum
Where the knowledge is shared
Menu
 Anthony's VBA Forum IndexHome Page
 Anthony's VBA Forum IndexForum Index
FAQFAQ
MemberlistMemberlist
UsergroupsUsergroups
RegisterRegister
ProfileProfile
Log in to check your private messagesMessages
Log inLogin/Out

Quick Search

Advanced Search

Links
Consulting
Products

Who's Online
[ Administrator ]
[ Moderator ]


need help: run-time error '1004': Application-defined or...

 
Post new topic   Reply to topic     Anthony's VBA Forum Index -> General Excel VBA
View previous topic :: View next topic  
Author Message
bgnew



Joined: 18 Nov 2008
Posts: 2

PostPosted: Tue Nov 18, 2008 10:16 pm    Post subject: need help: run-time error '1004': Application-defined or... Reply with quote

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! Laughing
Back to top
View user's profile Send private message
LB



Joined: 19 Nov 2008
Posts: 1

PostPosted: Wed Nov 19, 2008 3:32 am    Post subject: Reply with quote

Upload your files,This will help you better solve the problem
Back to top
View user's profile Send private message MSN Messenger
bgnew



Joined: 18 Nov 2008
Posts: 2

PostPosted: Wed Nov 19, 2008 3:41 am    Post subject: Reply with quote

Thanks, but I actually figured it out...it's probably not the most programmer friendly method, but it works! Happy

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Anthony's VBA Forum Index -> General Excel VBA All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
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