PC Review


Reply
Thread Tools Rate Thread

Clear a range of cells given 2 Cell addresses

 
 
ekareem
Guest
Posts: n/a
 
      31st Dec 2009
Hi
I want to be a able to clear a rectangular area.
I know the top most left corner address.
I know the bottom righ corner address.
all addresses are in the format r,c where r,c are integers.
So I know cell 1 to have coordinates (r1,c1) and cell 2 to have coordinates
(r2,c2).

How can I issue a clear command to clear all data and formulas in this region?

Thanks much in advance.

Ekareem
 
Reply With Quote
 
 
 
 
JP Ronse
Guest
Posts: n/a
 
      31st Dec 2009
Hi Ekareem,

Try ...

range(cells(r1,c1), cells(r2,c2)).clearcontents.

With kind regards,

JP


"ekareem" <(E-Mail Removed)> wrote in message
news:A19AD029-79BE-4EA6-93A0-(E-Mail Removed)...
> Hi
> I want to be a able to clear a rectangular area.
> I know the top most left corner address.
> I know the bottom righ corner address.
> all addresses are in the format r,c where r,c are integers.
> So I know cell 1 to have coordinates (r1,c1) and cell 2 to have
> coordinates
> (r2,c2).
>
> How can I issue a clear command to clear all data and formulas in this
> region?
>
> Thanks much in advance.
>
> Ekareem



 
Reply With Quote
 
ekareem
Guest
Posts: n/a
 
      31st Dec 2009
Hi
That worked real well.

If I may ask another question on the same subject,....What if the second
coordinates were not exactly known, say we want to clear the contents from
point (r1,c1) till the end of the sheet?

Thanks very much.

"JP Ronse" wrote:

> Hi Ekareem,
>
> Try ...
>
> range(cells(r1,c1), cells(r2,c2)).clearcontents.
>
> With kind regards,
>
> JP
>
>
> "ekareem" <(E-Mail Removed)> wrote in message
> news:A19AD029-79BE-4EA6-93A0-(E-Mail Removed)...
> > Hi
> > I want to be a able to clear a rectangular area.
> > I know the top most left corner address.
> > I know the bottom righ corner address.
> > all addresses are in the format r,c where r,c are integers.
> > So I know cell 1 to have coordinates (r1,c1) and cell 2 to have
> > coordinates
> > (r2,c2).
> >
> > How can I issue a clear command to clear all data and formulas in this
> > region?
> >
> > Thanks much in advance.
> >
> > Ekareem

>
>
> .
>

 
Reply With Quote
 
J_Knowles
Guest
Posts: n/a
 
      1st Jan 2010
Sub clearContentsMac()
'Clears A1:B2
Range(Cells(1, 1), Cells(2, 2)).ClearContents
End Sub

Sub clearContentsUsedRange()
'Clears all data on activesheet
ActiveSheet.UsedRange.ClearContents
End Sub

Sub clearContentsLastRowCol()
'clears data based on the No of columns in row 1 & No of rows in Col A
Dim lastrow As Long
Dim lastcol As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
' chg "A" to any column with max data to check
lastcol = Cells(1, Columns.Count).End(xlToLeft).Column
' chg 1 to any row with max data to check
Range(Cells(1, 1), Cells(lastrow, lastcol)).ClearContents
End Sub

HTH,
--
Data Hog


"ekareem" wrote:

> Hi
> That worked real well.
>
> If I may ask another question on the same subject,....What if the second
> coordinates were not exactly known, say we want to clear the contents from
> point (r1,c1) till the end of the sheet?
>
> Thanks very much.
>
> "JP Ronse" wrote:
>
> > Hi Ekareem,
> >
> > Try ...
> >
> > range(cells(r1,c1), cells(r2,c2)).clearcontents.
> >
> > With kind regards,
> >
> > JP
> >
> >
> > "ekareem" <(E-Mail Removed)> wrote in message
> > news:A19AD029-79BE-4EA6-93A0-(E-Mail Removed)...
> > > Hi
> > > I want to be a able to clear a rectangular area.
> > > I know the top most left corner address.
> > > I know the bottom righ corner address.
> > > all addresses are in the format r,c where r,c are integers.
> > > So I know cell 1 to have coordinates (r1,c1) and cell 2 to have
> > > coordinates
> > > (r2,c2).
> > >
> > > How can I issue a clear command to clear all data and formulas in this
> > > region?
> > >
> > > Thanks much in advance.
> > >
> > > Ekareem

> >
> >
> > .
> >

 
Reply With Quote
 
ekareem
Guest
Posts: n/a
 
      1st Jan 2010
Great - Thank you very much.
Regards,
EK

"J_Knowles" wrote:

> Sub clearContentsMac()
> 'Clears A1:B2
> Range(Cells(1, 1), Cells(2, 2)).ClearContents
> End Sub
>
> Sub clearContentsUsedRange()
> 'Clears all data on activesheet
> ActiveSheet.UsedRange.ClearContents
> End Sub
>
> Sub clearContentsLastRowCol()
> 'clears data based on the No of columns in row 1 & No of rows in Col A
> Dim lastrow As Long
> Dim lastcol As Long
> lastrow = Cells(Rows.Count, "A").End(xlUp).Row
> ' chg "A" to any column with max data to check
> lastcol = Cells(1, Columns.Count).End(xlToLeft).Column
> ' chg 1 to any row with max data to check
> Range(Cells(1, 1), Cells(lastrow, lastcol)).ClearContents
> End Sub
>
> HTH,
> --
> Data Hog
>
>
> "ekareem" wrote:
>
> > Hi
> > That worked real well.
> >
> > If I may ask another question on the same subject,....What if the second
> > coordinates were not exactly known, say we want to clear the contents from
> > point (r1,c1) till the end of the sheet?
> >
> > Thanks very much.
> >
> > "JP Ronse" wrote:
> >
> > > Hi Ekareem,
> > >
> > > Try ...
> > >
> > > range(cells(r1,c1), cells(r2,c2)).clearcontents.
> > >
> > > With kind regards,
> > >
> > > JP
> > >
> > >
> > > "ekareem" <(E-Mail Removed)> wrote in message
> > > news:A19AD029-79BE-4EA6-93A0-(E-Mail Removed)...
> > > > Hi
> > > > I want to be a able to clear a rectangular area.
> > > > I know the top most left corner address.
> > > > I know the bottom righ corner address.
> > > > all addresses are in the format r,c where r,c are integers.
> > > > So I know cell 1 to have coordinates (r1,c1) and cell 2 to have
> > > > coordinates
> > > > (r2,c2).
> > > >
> > > > How can I issue a clear command to clear all data and formulas in this
> > > > region?
> > > >
> > > > Thanks much in advance.
> > > >
> > > > Ekareem
> > >
> > >
> > > .
> > >

 
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
clear range of cells if another becomes blank =?Utf-8?B?Ymdn?= Microsoft Excel Worksheet Functions 2 17th Jan 2007 11:32 PM
Clear a range of cells Joe@excel Microsoft Excel Discussion 6 25th Nov 2005 06:28 AM
Clear cells range if certain cells are all empty gschimek - ExcelForums.com Microsoft Excel Programming 6 13th May 2005 10:38 PM
Clear range of cells in different worksheet Tim Kelley Microsoft Excel Programming 1 30th Dec 2004 06:54 PM
Named Range Cells vs. Absolute Cell Addresses Mike Short Microsoft Excel Programming 4 29th Nov 2003 11:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:36 PM.