PC Review


Reply
Thread Tools Rate Thread

delete last line of numbers

 
 
Gordon
Guest
Posts: n/a
 
      8th Jul 2008
Hi...

I import a block of text from another sheet with a simple macro but want to
delete the last line that holds numerical values. The block of data varies in
depth and the line to removed can vary say from line 20 - 8000. I need some
code that will identify when the numercial data stops and to delete the line
on which the data appears last.

Anything out there?

Cheers

Gordon.
 
Reply With Quote
 
 
 
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      8th Jul 2008
Where is this block of text at... In a simple String variable within your
code? In a String array within your code? In a single cell in your
worksheet? Or split up into rows (by lines) in your worksheet? Your use of
the word "import" seems to suggest it is in the worksheet somewhere, but
your use of the word "lines" instead of "rows" seems to suggest it is in a
variable somewhere. Also, you said "the last line that holds numerical
values" which suggests this "line" has more than one value in it... can you
post a sample of what that line (or row if in a worksheet) would look like
(I'm interested in how the multiple values are delimited)?

Rick


"Gordon" <(E-Mail Removed)> wrote in message
news:EB6C0EB8-17A5-4FC5-BFD2-(E-Mail Removed)...
> Hi...
>
> I import a block of text from another sheet with a simple macro but want
> to
> delete the last line that holds numerical values. The block of data varies
> in
> depth and the line to removed can vary say from line 20 - 8000. I need
> some
> code that will identify when the numercial data stops and to delete the
> line
> on which the data appears last.
>
> Anything out there?
>
> Cheers
>
> Gordon.


 
Reply With Quote
 
Tom Ogilvy
Guest
Posts: n/a
 
      8th Jul 2008
Assume that column 1 can be used to make the determination.

Dim r as Range, r1 as Range, r2 as Range

' get all cells in the column that contain numbers
set r = columns(1).specialcells(xlconstants,xlnumbers)

get the last set of cells that contain numbers
set r1 = r.areas(r.areas.count)

get the last cell in the last set of cells that contain numbers
set r2 = r1(r1.count)

msgbox r2.address


--
Regards,
Tom Ogilvy

"Gordon" wrote:

> Hi...
>
> I import a block of text from another sheet with a simple macro but want to
> delete the last line that holds numerical values. The block of data varies in
> depth and the line to removed can vary say from line 20 - 8000. I need some
> code that will identify when the numercial data stops and to delete the line
> on which the data appears last.
>
> Anything out there?
>
> Cheers
>
> Gordon.

 
Reply With Quote
 
Gordon
Guest
Posts: n/a
 
      8th Jul 2008
Hi Rick...

Apologies for mixed terminology. It's much simpler than that. A block of
data is dumped in at cell A6 and goes across to column U. The data that goes
down however can go from row 6 to row 8000. The code needs to idnetify the
last line (not a gap) and then delete the last line, and nbot identify the
new last line.

Make sense!

G

"Rick Rothstein (MVP - VB)" wrote:

> Where is this block of text at... In a simple String variable within your
> code? In a String array within your code? In a single cell in your
> worksheet? Or split up into rows (by lines) in your worksheet? Your use of
> the word "import" seems to suggest it is in the worksheet somewhere, but
> your use of the word "lines" instead of "rows" seems to suggest it is in a
> variable somewhere. Also, you said "the last line that holds numerical
> values" which suggests this "line" has more than one value in it... can you
> post a sample of what that line (or row if in a worksheet) would look like
> (I'm interested in how the multiple values are delimited)?
>
> Rick
>
>
> "Gordon" <(E-Mail Removed)> wrote in message
> news:EB6C0EB8-17A5-4FC5-BFD2-(E-Mail Removed)...
> > Hi...
> >
> > I import a block of text from another sheet with a simple macro but want
> > to
> > delete the last line that holds numerical values. The block of data varies
> > in
> > depth and the line to removed can vary say from line 20 - 8000. I need
> > some
> > code that will identify when the numercial data stops and to delete the
> > line
> > on which the data appears last.
> >
> > Anything out there?
> >
> > Cheers
> >
> > Gordon.

>
>

 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      8th Jul 2008
Assuming Column A always has an entry in it for each data line, you can
identify the last line of data like this...

LastDataRow = Cells(Rows.Count, "A").End(xlUp).Row

Although you should probably qualify the Cells property with a reference to
the worksheet it is on.

I'm not 100% sure this is what you actually want, though, as your initial
post seemed to indicate you had regular text mixed with numerical text and
the above only find the last line no matter what type of data is in it.

Rick


"Gordon" <(E-Mail Removed)> wrote in message
news:45395FF2-4AFE-4EC4-BAD7-(E-Mail Removed)...
> Hi Rick...
>
> Apologies for mixed terminology. It's much simpler than that. A block of
> data is dumped in at cell A6 and goes across to column U. The data that
> goes
> down however can go from row 6 to row 8000. The code needs to idnetify the
> last line (not a gap) and then delete the last line, and nbot identify the
> new last line.
>
> Make sense!
>
> G
>
> "Rick Rothstein (MVP - VB)" wrote:
>
>> Where is this block of text at... In a simple String variable within your
>> code? In a String array within your code? In a single cell in your
>> worksheet? Or split up into rows (by lines) in your worksheet? Your use
>> of
>> the word "import" seems to suggest it is in the worksheet somewhere, but
>> your use of the word "lines" instead of "rows" seems to suggest it is in
>> a
>> variable somewhere. Also, you said "the last line that holds numerical
>> values" which suggests this "line" has more than one value in it... can
>> you
>> post a sample of what that line (or row if in a worksheet) would look
>> like
>> (I'm interested in how the multiple values are delimited)?
>>
>> Rick
>>
>>
>> "Gordon" <(E-Mail Removed)> wrote in message
>> news:EB6C0EB8-17A5-4FC5-BFD2-(E-Mail Removed)...
>> > Hi...
>> >
>> > I import a block of text from another sheet with a simple macro but
>> > want
>> > to
>> > delete the last line that holds numerical values. The block of data
>> > varies
>> > in
>> > depth and the line to removed can vary say from line 20 - 8000. I need
>> > some
>> > code that will identify when the numercial data stops and to delete
>> > the
>> > line
>> > on which the data appears last.
>> >
>> > Anything out there?
>> >
>> > Cheers
>> >
>> > Gordon.

>>
>>


 
Reply With Quote
 
Gary''s Student
Guest
Posts: n/a
 
      8th Jul 2008
This auumes the block includes column A. It starts working backwards and
deletes the FIRST numeric row it finds (working backwards):

Sub flash()
n = Cells(Rows.Count, "A").End(xlUp).Row
For i = n To 1 Step -1
If IsNumeric(Cells(i, "A").Value) Then
Cells(i, "A").EntireRow.Delete
Exit Sub
End If
Next
End Sub
--
Gary''s Student - gsnu200794


"Gordon" wrote:

> Hi...
>
> I import a block of text from another sheet with a simple macro but want to
> delete the last line that holds numerical values. The block of data varies in
> depth and the line to removed can vary say from line 20 - 8000. I need some
> code that will identify when the numercial data stops and to delete the line
> on which the data appears last.
>
> Anything out there?
>
> Cheers
>
> Gordon.

 
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 can I add record numbers or line numbers to a query? StratfordWard Microsoft Access Queries 1 1st Aug 2008 11:40 PM
How do I get text in a legal document to line up with line numbers sunshine97236 Microsoft Word Document Management 1 25th Jan 2008 07:33 PM
Line Numbers in reports (per line, not per record) =?Utf-8?B?QXByaWwgLSBsaW5lIG51bWJlcnM=?= Microsoft Access Reports 0 1st Jun 2006 04:57 PM
Delete line change and remove space between all numbers. =?Utf-8?B?aGFucyBqYWNvYnNlbg==?= Microsoft Word Document Management 1 4th Jan 2006 10:58 AM
Line numbers some numbers are blue some are black =?Utf-8?B?bmt0MTIyODY2?= Microsoft Excel Misc 2 29th Sep 2005 09:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:42 PM.