Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Clear rows with no data?

I am using VBA code I found on this board to populate a summary sheet with
data from other worksheets in the same workbook. The code is as follows:

Sub SheetList()
For Each ws In Worksheets
i = i + 1
Cells(i, 1) = ws.Name
Next
End Sub

This is working great for what I need it to do, however, when I delete a
worksheet it creates a broken reference for the last row in the set because
my formulas in the rest of the row depend on references to the first cell in
the row to locate the worksheet they are pulling information from (INDIRECT
references for those in the know). Deleting two worksheets results in the
last two rows worth of references being broken, and so on. How can I edit
this code to both generate the list like I want it to, and then delete the
rest of the entries in column "A" to clear the bad references from that row
of information? I am ok with these rows showing a zero, but would be
blissfully happy if someone could point me to some code that will move the
totals line up and down as I add or subtract worksheets to the workbook!
Thanks for your time!
-Kai
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Clear rows with no data?

How about
Dim myWS as Worksheet
Dim lRow as long
Dim myRange as range

Set myWS = activesheet

lRow = myWS.cells(rows.count,1).end(xlup).row
set myrange = myWS.cells(1,1).resize(lrow,1)
myrange.clearcontents
set myrange = nothing

'Now run your code

HTH,
Barb Reinhardt

"Kai Cunningham" wrote:

I am using VBA code I found on this board to populate a summary sheet with
data from other worksheets in the same workbook. The code is as follows:

Sub SheetList()
For Each ws In mywb.Worksheets
i = i + 1
Cells(i, 1) = ws.Name
Next
End Sub

This is working great for what I need it to do, however, when I delete a
worksheet it creates a broken reference for the last row in the set because
my formulas in the rest of the row depend on references to the first cell in
the row to locate the worksheet they are pulling information from (INDIRECT
references for those in the know). Deleting two worksheets results in the
last two rows worth of references being broken, and so on. How can I edit
this code to both generate the list like I want it to, and then delete the
rest of the entries in column "A" to clear the bad references from that row
of information? I am ok with these rows showing a zero, but would be
blissfully happy if someone could point me to some code that will move the
totals line up and down as I add or subtract worksheets to the workbook!
Thanks for your time!
-Kai

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Clear rows with no data?

VBA is hitting a compile error when it gets to "Set" of "Set myWS =
activesheet" saying it has an invalid outside procedure error when I try to
compile it. Any ideas?

"Barb Reinhardt" wrote:

How about
Dim myWS as Worksheet
Dim lRow as long
Dim myRange as range

Set myWS = activesheet

lRow = myWS.cells(rows.count,1).end(xlup).row
set myrange = myWS.cells(1,1).resize(lrow,1)
myrange.clearcontents
set myrange = nothing

'Now run your code

HTH,
Barb Reinhardt

"Kai Cunningham" wrote:

I am using VBA code I found on this board to populate a summary sheet with
data from other worksheets in the same workbook. The code is as follows:

Sub SheetList()
For Each ws In mywb.Worksheets
i = i + 1
Cells(i, 1) = ws.Name
Next
End Sub

This is working great for what I need it to do, however, when I delete a
worksheet it creates a broken reference for the last row in the set because
my formulas in the rest of the row depend on references to the first cell in
the row to locate the worksheet they are pulling information from (INDIRECT
references for those in the know). Deleting two worksheets results in the
last two rows worth of references being broken, and so on. How can I edit
this code to both generate the list like I want it to, and then delete the
rest of the entries in column "A" to clear the bad references from that row
of information? I am ok with these rows showing a zero, but would be
blissfully happy if someone could point me to some code that will move the
totals line up and down as I add or subtract worksheets to the workbook!
Thanks for your time!
-Kai

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Clear rows with no data?

Barb just posted the "guts" of the routine.

Option Explicit
Sub YourMacNameHere()

Dim myWS as Worksheet
Dim lRow as long
Dim myRange as range
dim ws as worksheet
dim i as long

Set myWS = activesheet

lRow = myWS.cells(rows.count,1).end(xlup).row
set myrange = myWS.cells(1,1).resize(lrow,1)
myrange.clearcontents
set myrange = nothing

'Then either call your code:
'Call SheetList
'or add it directly he

For Each ws In Worksheets
i = i + 1
myws.Cells(i, 1) = ws.Name
Next ws

End Sub

Kai Cunningham wrote:

VBA is hitting a compile error when it gets to "Set" of "Set myWS =
activesheet" saying it has an invalid outside procedure error when I try to
compile it. Any ideas?

"Barb Reinhardt" wrote:

How about
Dim myWS as Worksheet
Dim lRow as long
Dim myRange as range

Set myWS = activesheet

lRow = myWS.cells(rows.count,1).end(xlup).row
set myrange = myWS.cells(1,1).resize(lrow,1)
myrange.clearcontents
set myrange = nothing

'Now run your code

HTH,
Barb Reinhardt

"Kai Cunningham" wrote:

I am using VBA code I found on this board to populate a summary sheet with
data from other worksheets in the same workbook. The code is as follows:

Sub SheetList()
For Each ws In mywb.Worksheets
i = i + 1
Cells(i, 1) = ws.Name
Next
End Sub

This is working great for what I need it to do, however, when I delete a
worksheet it creates a broken reference for the last row in the set because
my formulas in the rest of the row depend on references to the first cell in
the row to locate the worksheet they are pulling information from (INDIRECT
references for those in the know). Deleting two worksheets results in the
last two rows worth of references being broken, and so on. How can I edit
this code to both generate the list like I want it to, and then delete the
rest of the entries in column "A" to clear the bad references from that row
of information? I am ok with these rows showing a zero, but would be
blissfully happy if someone could point me to some code that will move the
totals line up and down as I add or subtract worksheets to the workbook!
Thanks for your time!
-Kai


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Clear rows with no data?


Thanks a ton! Newer user here and I'm still not familiar with the
programming aspect, so the step-by-step total process is much appreciated!
-Kai
"Dave Peterson" wrote:

Barb just posted the "guts" of the routine.

Option Explicit
Sub YourMacNameHere()

Dim myWS as Worksheet
Dim lRow as long
Dim myRange as range
dim ws as worksheet
dim i as long

Set myWS = activesheet

lRow = myWS.cells(rows.count,1).end(xlup).row
set myrange = myWS.cells(1,1).resize(lrow,1)
myrange.clearcontents
set myrange = nothing

'Then either call your code:
'Call SheetList
'or add it directly he

For Each ws In Worksheets
i = i + 1
myws.Cells(i, 1) = ws.Name
Next ws

End Sub




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
clear the clear the web page email attachment lines MCrider Excel Discussion (Misc queries) 0 November 11th 07 10:05 PM
How do I clear all cells from all rows except the first row in Sheet1? Michael[_45_] Excel Programming 3 May 17th 07 03:29 PM
Creating a graph with existing data...clear data after save Cam Neeson Excel Programming 3 June 15th 06 06:37 PM
Help to clear data & delete rows Eddy Stan Excel Programming 1 March 11th 06 10:29 AM
macro to clear rows Peter H Excel Programming 6 July 23rd 03 08:50 PM


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

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

About Us

"It's about Microsoft Excel"