PC Review


Reply
Thread Tools Rate Thread

compile error, need to simplify/shorten

 
 
peterlaramore@gmail.com
Guest
Posts: n/a
 
      10th Nov 2007
I know this isn't the best way to go about this, but I a learning
here. . .

I am using this to update stock prices from a Google Finance query. I
have a list of about 200 stocks, and when I run the below query for
200 cells I get a "Compile Error: Procedure too large". Can anybody
show me the light simplifying this? Thanks much.

Range("B2").Select
Selection.Copy
Sheets("Sheet2").Select
Range("A1").Select
ActiveSheet.Paste
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A2").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Selection.Copy
Sheets("Sheet1").Select
Range("M2").Select
ActiveSheet.Paste
ActiveSheet.Paste
Application.CutCopyMode = False
Range("B3").Select
Selection.Copy
Sheets("Sheet2").Select
Range("A1").Select
ActiveSheet.Paste
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A2").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Selection.Copy
Sheets("Sheet1").Select
Range("M3").Select
ActiveSheet.Paste
ActiveSheet.Paste
Application.CutCopyMode = False

And so on. . .

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sk1C?=
Guest
Posts: n/a
 
      10th Nov 2007
You rarely need to select or activate anything in order to work with it.
These lines could be changed from
> Range("B2").Select
> Selection.Copy
> Sheets("Sheet2").Select
> Range("A1").Select
> ActiveSheet.Paste
> ActiveSheet.Paste
> Application.CutCopyMode = False


To
Sheets("Sheet1").Range("B2").Copy Sheets("Sheet2").Range("A1")

It appears you are copying values from Sheet1 column B to Sheet2 A1,
refreshing a querytable in Sheet2 A2, then copying A2 back to Sheet1 into
column M. Maybe something similar to this is what you are looking for:

Sub test()
Dim rngSource As Range
Dim rngDest As Range
Dim rngQuery As Range
Dim rngCell As Range

Set rngSource = Sheets("Sheet1").Range("B2:B3") '<CHANGE
Set rngDest = Sheets("Sheet2").Range("A1")
Set rngQuery = Sheets("Sheet2").Range("A2")

For Each rngCell In rngSource.Cells
rngCell.Copy rngDest
With rngQuery
.QueryTable.Refresh BackgroundQuery:=False
.Copy rngSource.Parent.Range("M" & rngCell.Row)
End With
Next rngCell

End Sub

"(E-Mail Removed)" wrote:

> I know this isn't the best way to go about this, but I a learning
> here. . .
>
> I am using this to update stock prices from a Google Finance query. I
> have a list of about 200 stocks, and when I run the below query for
> 200 cells I get a "Compile Error: Procedure too large". Can anybody
> show me the light simplifying this? Thanks much.
>
> Range("B2").Select
> Selection.Copy
> Sheets("Sheet2").Select
> Range("A1").Select
> ActiveSheet.Paste
> ActiveSheet.Paste
> Application.CutCopyMode = False
> Range("A2").Select
> Selection.QueryTable.Refresh BackgroundQuery:=False
> Selection.Copy
> Sheets("Sheet1").Select
> Range("M2").Select
> ActiveSheet.Paste
> ActiveSheet.Paste
> Application.CutCopyMode = False
> Range("B3").Select
> Selection.Copy
> Sheets("Sheet2").Select
> Range("A1").Select
> ActiveSheet.Paste
> ActiveSheet.Paste
> Application.CutCopyMode = False
> Range("A2").Select
> Selection.QueryTable.Refresh BackgroundQuery:=False
> Selection.Copy
> Sheets("Sheet1").Select
> Range("M3").Select
> ActiveSheet.Paste
> ActiveSheet.Paste
> Application.CutCopyMode = False
>
> And so on. . .
>
>

 
Reply With Quote
 
peterlaramore@gmail.com
Guest
Posts: n/a
 
      10th Nov 2007
On Nov 9, 11:17 pm, JMB <J...@discussions.microsoft.com> wrote:
> You rarely need to select or activate anything in order to work with it.
> These lines could be changed from
>
> > Range("B2").Select
> > Selection.Copy
> > Sheets("Sheet2").Select
> > Range("A1").Select
> > ActiveSheet.Paste
> > ActiveSheet.Paste
> > Application.CutCopyMode = False

>
> To
> Sheets("Sheet1").Range("B2").Copy Sheets("Sheet2").Range("A1")
>
> It appears you are copying values from Sheet1 column B to Sheet2 A1,
> refreshing a querytable in Sheet2 A2, then copying A2 back to Sheet1 into
> column M. Maybe something similar to this is what you are looking for:
>
> Sub test()
> Dim rngSource As Range
> Dim rngDest As Range
> Dim rngQuery As Range
> Dim rngCell As Range
>
> Set rngSource = Sheets("Sheet1").Range("B2:B3") '<CHANGE
> Set rngDest = Sheets("Sheet2").Range("A1")
> Set rngQuery = Sheets("Sheet2").Range("A2")
>
> For Each rngCell In rngSource.Cells
> rngCell.Copy rngDest
> With rngQuery
> .QueryTable.Refresh BackgroundQuery:=False
> .Copy rngSource.Parent.Range("M" & rngCell.Row)
> End With
> Next rngCell
>
> End Sub
>
> "peterlaram...@gmail.com" wrote:
> > I know this isn't the best way to go about this, but I a learning
> > here. . .

>
> > I am using this to update stock prices from a Google Finance query. I
> > have a list of about 200 stocks, and when I run the below query for
> > 200 cells I get a "CompileError: Procedure too large". Can anybody
> > show me the light simplifying this? Thanks much.

>
> > Range("B2").Select
> > Selection.Copy
> > Sheets("Sheet2").Select
> > Range("A1").Select
> > ActiveSheet.Paste
> > ActiveSheet.Paste
> > Application.CutCopyMode = False
> > Range("A2").Select
> > Selection.QueryTable.Refresh BackgroundQuery:=False
> > Selection.Copy
> > Sheets("Sheet1").Select
> > Range("M2").Select
> > ActiveSheet.Paste
> > ActiveSheet.Paste
> > Application.CutCopyMode = False
> > Range("B3").Select
> > Selection.Copy
> > Sheets("Sheet2").Select
> > Range("A1").Select
> > ActiveSheet.Paste
> > ActiveSheet.Paste
> > Application.CutCopyMode = False
> > Range("A2").Select
> > Selection.QueryTable.Refresh BackgroundQuery:=False
> > Selection.Copy
> > Sheets("Sheet1").Select
> > Range("M3").Select
> > ActiveSheet.Paste
> > ActiveSheet.Paste
> > Application.CutCopyMode = False

>
> > And so on. . .


Thanks, I'll try that

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Export report to Excel, Error message "Compile Error: Argument not mc Microsoft Access External Data 0 16th Jul 2009 09:11 PM
simplify procedure to get rid of 0 error values in a spreadsheet =?Utf-8?B?RnJlZGVyaWM=?= Microsoft Excel Worksheet Functions 1 8th Feb 2006 04:47 AM
VBAProject name compile error, not defined at compile time Matthew Dodds Microsoft Excel Programming 1 13th Dec 2005 07:17 PM
Compile error. in table-level validation expression. (Error 3320) =?Utf-8?B?RG9ubmE=?= Microsoft Access Forms 4 21st Mar 2005 08:13 PM
error message in Winword. ( Compile error in hidden module: AutoE. =?Utf-8?B?TXkgRXJyb3IgUHJvYmxlbQ==?= Microsoft Access Getting Started 1 4th Oct 2004 02:52 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:11 PM.