PC Review


Reply
Thread Tools Rate Thread

Average data and delete a row-need help

 
 
=?Utf-8?B?Sm9obg==?=
Guest
Posts: n/a
 
      10th Nov 2007
Hello All, I average the data in cells B6 to B36 and place average one cell
over in C36. Once this is done, I want to delete row 6. I get an error at
line "selection.Delete shift:=xlUp" of "Object variable or With block
variable not set". Don't understand what is wrong. Below is what I have and
appreciate any help. Thanks.

Dim selection As range
'Dim myobject As range
Dim i As Long
For i = 6 To 100

Cells(65000, 2).End(xlUp).Offset(0, 1).Select
Cells(i, 3).FormulaR1C1 = "=AVERAGE(R[-30]C[-1]:RC[-1])"
Exit For
Next i
Rows("6:6").Select
selection.Delete shift:=xlUp

End Sub

--
John
 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      10th Nov 2007
The problem is that you have a variable named "selection" that is never set
to anything. That's why you get the "not set" error. "Selection" is a
reserved word in Excel/VBA and therefore should not be used as a variable
name. Delete the line

Dim selection As Range

and your code should work.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"John" <(E-Mail Removed)> wrote in message
news:4BD40144-ED2D-4826-AA41-(E-Mail Removed)...
> Hello All, I average the data in cells B6 to B36 and place average one
> cell
> over in C36. Once this is done, I want to delete row 6. I get an error at
> line "selection.Delete shift:=xlUp" of "Object variable or With block
> variable not set". Don't understand what is wrong. Below is what I have
> and
> appreciate any help. Thanks.
>
> Dim selection As range
> 'Dim myobject As range
> Dim i As Long
> For i = 6 To 100
>
> Cells(65000, 2).End(xlUp).Offset(0, 1).Select
> Cells(i, 3).FormulaR1C1 = "=AVERAGE(R[-30]C[-1]:RC[-1])"
> Exit For
> Next i
> Rows("6:6").Select
> selection.Delete shift:=xlUp
>
> End Sub
>
> --
> John


 
Reply With Quote
 
=?Utf-8?B?Sm9obg==?=
Guest
Posts: n/a
 
      10th Nov 2007
Thanks, that works for me. So simple.
--
John


"John" wrote:

> Hello All, I average the data in cells B6 to B36 and place average one cell
> over in C36. Once this is done, I want to delete row 6. I get an error at
> line "selection.Delete shift:=xlUp" of "Object variable or With block
> variable not set". Don't understand what is wrong. Below is what I have and
> appreciate any help. Thanks.
>
> Dim selection As range
> 'Dim myobject As range
> Dim i As Long
> For i = 6 To 100
>
> Cells(65000, 2).End(xlUp).Offset(0, 1).Select
> Cells(i, 3).FormulaR1C1 = "=AVERAGE(R[-30]C[-1]:RC[-1])"
> Exit For
> Next i
> Rows("6:6").Select
> selection.Delete shift:=xlUp
>
> End Sub
>
> --
> John

 
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
How do I average hourly data into daily data? Lindsey Microsoft Excel Misc 1 30th Mar 2009 05:05 PM
Average row of Data using VBA Carlee Microsoft Excel Programming 5 3rd Feb 2008 09:28 PM
Average when No Data =?Utf-8?B?Y2FybA==?= Microsoft Excel Worksheet Functions 4 13th Jan 2006 07:39 PM
How do you average if your data contains a 0? =?Utf-8?B?cmFzNzEx?= Microsoft Excel Worksheet Functions 14 8th Nov 2005 03:55 AM
Trying to aggregate weekly data into monthly average data Karen 1144 Microsoft Excel Misc 4 6th Nov 2003 12:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:20 AM.