Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Search for a string and extract it?

Hey guys,
So I'm guessing this will be simple:

I have large blocks of text inside a single cell. I want to search
through the text and extract a single string, as such:

(Contents of a Cell)

blah blah
blah blah
Disk Size: 50 GB <-- I'd like to pull out just "50" and put it in its
own cell
blah blah
blah blah

I'd like to do this via a vba function on a spreadsheet that would
have lots of cells of such text blocks -- so the end result is I have
a list of Disk Sizes that I can then total up.

Any ideas?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Search for a string and extract it?

One way:

Public Function DiskSize(ByVal sINPUT As String) As Double
Const sSEARCH As String = "Disk Size:"
Dim dResult As Double
Dim nPos As Long
Dim i As Long
nPos = InStr(UCase(sINPUT), UCase(sSEARCH))
If nPos 0 Then
sINPUT = Trim(Mid(sINPUT, nPos + Len(sSEARCH)))
For i = 1 To Len(sINPUT)
If Not IsNumeric(Mid(sINPUT, i, 1)) Then Exit For
Next i
sINPUT = Left(sINPUT, i - 1)
If IsNumeric(sINPUT) Then _
DiskSize = CDbl(sINPUT)
End If
End Function



In article om,
wrote:

Hey guys,
So I'm guessing this will be simple:

I have large blocks of text inside a single cell. I want to search
through the text and extract a single string, as such:

(Contents of a Cell)

blah blah
blah blah
Disk Size: 50 GB <-- I'd like to pull out just "50" and put it in its
own cell
blah blah
blah blah

I'd like to do this via a vba function on a spreadsheet that would
have lots of cells of such text blocks -- so the end result is I have
a list of Disk Sizes that I can then total up.

Any ideas?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Search for a string and extract it?

Are all the filesizes in GB? You plan will not work if you have combination
of bytes, KB,MB, and GB

Sub getfilesize()


For Each cell In ActiveCell

numberstring = Mid(cell, InStr(cell, "Disk Size:") + 10)
Size = Val(numberstring)

Next cell

End Sub


" wrote:

Hey guys,
So I'm guessing this will be simple:

I have large blocks of text inside a single cell. I want to search
through the text and extract a single string, as such:

(Contents of a Cell)

blah blah
blah blah
Disk Size: 50 GB <-- I'd like to pull out just "50" and put it in its
own cell
blah blah
blah blah

I'd like to do this via a vba function on a spreadsheet that would
have lots of cells of such text blocks -- so the end result is I have
a list of Disk Sizes that I can then total up.

Any ideas?


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
Search and extract Gordon[_2_] Excel Programming 1 September 4th 06 11:20 AM
Wildcard search for string within a string? Ed Excel Programming 0 June 8th 06 11:28 PM
to search for a string and affect data if it finds the string? Shwaman Excel Worksheet Functions 1 January 11th 06 12:56 AM
search a string withing a string : find / search hangs itarnak[_9_] Excel Programming 4 October 24th 05 03:19 PM
VBA function : How to search a string in another string? bibi-phoque Excel Programming 5 April 19th 05 06:24 PM


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