Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 125
Default macro to remove cells (not absolute)

Hi, I want to find Grand Total: and then delete the 4 cells after it so that
the 4 cells underneath move up. The rows and columns are not absolute (will
be different every time I run the macro).

How do I code for this?

TIA!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,805
Default macro to remove cells (not absolute)

Try
Sub deleteCells()
Range("A1").Select
Cells.Find(What:="Grand Total:", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(4, 0)).Delete
End Sub

"Karin" wrote:

Hi, I want to find Grand Total: and then delete the 4 cells after it so that
the 4 cells underneath move up. The rows and columns are not absolute (will
be different every time I run the macro).

How do I code for this?

TIA!

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default macro to remove cells (not absolute)

Sub Karin()
Dim s As String, r As Range
s = "Grand Total"
For Each r In ActiveSheet.UsedRange
If r.Value = s Then
Range(r.Offset(1, 0), r.Offset(4, 0)).Delete Shift:=xlUp
Exit Sub
End If
Next
End Sub

--
Gary''s Student - gsnu200838
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,805
Default macro to remove cells (not absolute)

Sorry, missed adding Shift:=xlUp

Use this one...

Sub Macro1()
Range("A1").Select
Cells.Find(What:="Grand Total:", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(4, 0)).Delete Shift:=xlUp
End Sub

"Sheeloo" wrote:

Try
Sub deleteCells()
Range("A1").Select
Cells.Find(What:="Grand Total:", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(4, 0)).Delete
End Sub

"Karin" wrote:

Hi, I want to find Grand Total: and then delete the 4 cells after it so that
the 4 cells underneath move up. The rows and columns are not absolute (will
be different every time I run the macro).

How do I code for this?

TIA!

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 125
Default macro to remove cells (not absolute)

It does not seem to be working - does it need to select the 4 cells before
the Delete?

"Gary''s Student" wrote:

Sub Karin()
Dim s As String, r As Range
s = "Grand Total"
For Each r In ActiveSheet.UsedRange
If r.Value = s Then
Range(r.Offset(1, 0), r.Offset(4, 0)).Delete Shift:=xlUp
Exit Sub
End If
Next
End Sub

--
Gary''s Student - gsnu200838



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 125
Default macro to remove cells (not absolute)

It seems to be deleting 4 rows down, not the 4 cells to the right.

"Sheeloo" wrote:

Try
Sub deleteCells()
Range("A1").Select
Cells.Find(What:="Grand Total:", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(4, 0)).Delete
End Sub

"Karin" wrote:

Hi, I want to find Grand Total: and then delete the 4 cells after it so that
the 4 cells underneath move up. The rows and columns are not absolute (will
be different every time I run the macro).

How do I code for this?

TIA!

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 225
Default macro to remove cells (not absolute)

In that case use...
(It will delete the first four cells to the right of the cell containing
Grand Total:

You can play around with the number in OFFSET..
Offset(0, 1) means 0 row down and 1 column to right...

Sub Macro1()
Range("A1").Select
Cells.Find(What:="Grand Total:", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Range(ActiveCell.Offset(0, 1), ActiveCell.Offset(0, 4)).Delete Shift:=xlUp
End Sub

"Karin" wrote:

It seems to be deleting 4 rows down, not the 4 cells to the right.

"Sheeloo" wrote:

Try
Sub deleteCells()
Range("A1").Select
Cells.Find(What:="Grand Total:", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate

Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(4, 0)).Delete
End Sub

"Karin" wrote:

Hi, I want to find Grand Total: and then delete the 4 cells after it so that
the 4 cells underneath move up. The rows and columns are not absolute (will
be different every time I run the macro).

How do I code for this?

TIA!

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default macro to remove cells (not absolute)

My error.

Replace the line:
s="Grand Total"
with:
s="Grand Total:"
--
Gary''s Student - gsnu200839


"Karin" wrote:

It does not seem to be working - does it need to select the 4 cells before
the Delete?

"Gary''s Student" wrote:

Sub Karin()
Dim s As String, r As Range
s = "Grand Total"
For Each r In ActiveSheet.UsedRange
If r.Value = s Then
Range(r.Offset(1, 0), r.Offset(4, 0)).Delete Shift:=xlUp
Exit Sub
End If
Next
End Sub

--
Gary''s Student - gsnu200838

  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 125
Default macro to remove cells (not absolute)

Thank you - I had fixed that. :) I think you are going down 4 rows and
deleting rather than going over 4 cells - also I am on the grand total line,
so I need to delete the 4 cells on that line so that the 4 cells on the line
below come up.

Original:
Range(r.Offset(1, 0), r.Offset(4, 0)).Delete Shift:=xlUp

Modified:
r.Offset(0, 2)).Delete Shift:=xlUp
r.Offset(0, 3)).Delete Shift:=xlUp
r.Offset(0, 4)).Delete Shift:=xlUp

This is working. Not sure if I can combine the 3.
Thank you very much for your assistance.

"Gary''s Student" wrote:

My error.

Replace the line:
s="Grand Total"
with:
s="Grand Total:"
--
Gary''s Student - gsnu200839


"Karin" wrote:

It does not seem to be working - does it need to select the 4 cells before
the Delete?

"Gary''s Student" wrote:

Sub Karin()
Dim s As String, r As Range
s = "Grand Total"
For Each r In ActiveSheet.UsedRange
If r.Value = s Then
Range(r.Offset(1, 0), r.Offset(4, 0)).Delete Shift:=xlUp
Exit Sub
End If
Next
End Sub

--
Gary''s Student - gsnu200838

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
absolute cell reference macro rk0909 Excel Discussion (Misc queries) 4 November 7th 09 12:37 AM
Pivot Macro - select absolute value Todd1 Excel Discussion (Misc queries) 5 May 17th 06 05:51 AM
How to chnge 35 relative cells to 35 absolute cells at one time. Susan A at Millennium Medical Excel Worksheet Functions 3 March 7th 06 08:12 PM
Help with absolute references in a macro Manty Excel Discussion (Misc queries) 5 January 13th 06 02:26 PM
Macro or Formula to remove Text from Cells smck Excel Worksheet Functions 6 May 11th 05 03:22 AM


All times are GMT +1. The time now is 10:41 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"