Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Average data and delete a row-need help

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Average data and delete a row-need help

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" wrote in message
...
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Average data and delete a row-need help

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I average hourly data into daily data? Lindsey Excel Discussion (Misc queries) 1 March 30th 09 05:05 PM
average 4 data from different sheets [email protected] Excel Discussion (Misc queries) 1 March 30th 06 12:23 AM
Average when No Data carl Excel Worksheet Functions 4 January 13th 06 07:39 PM
How do you average if your data contains a 0? ras711 Excel Worksheet Functions 14 November 8th 05 03:55 AM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"