Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Find String within Cell

I have a spreadsheet which uses concatenated data as the basis for sumif
calculations looking at another spreadsheet. In separate columns however, I
want to be able to split out the concatenated data.

Column AM has my concatenated data as follows:

Glasgow Property Freehold
South Yorkshire Property Shorthold Lease
Edinburgh Other Telephone System

I want to be able to search in column AM, find the Region (Glasgow,
Edinburgh....) and return that region into column B of the same row. I have
approx 20 regions that I am looking for which are listed in a range called
"Opcos"

I think it's vbTextCompare I need to use but don't know where to start with
writing the code to do this. Could someone please help me with the code
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Find String within Cell

Try this


Sub ExtractLocation()


LastrowF = Cells(Rows.Count, "F").End(xlUp).Row
Set Opcos = Range(Cells(1, "F"), Cells(LastrowF, "F"))

LastrowAM = Cells(Rows.Count, "AM").End(xlUp).Row
Set AMRange = Range(Cells(1, "AM"), Cells(LastrowAM, "AM"))


For Each cell In Opcos

Set c = AMRange.Find(cell, LookIn:=xlValues)
If Not c Is Nothing Then
Cells(cell.Row, "B") = cell

End If

Next cell

End Sub

"Karen McKenzie" wrote:

I have a spreadsheet which uses concatenated data as the basis for sumif
calculations looking at another spreadsheet. In separate columns however, I
want to be able to split out the concatenated data.

Column AM has my concatenated data as follows:

Glasgow Property Freehold
South Yorkshire Property Shorthold Lease
Edinburgh Other Telephone System

I want to be able to search in column AM, find the Region (Glasgow,
Edinburgh....) and return that region into column B of the same row. I have
approx 20 regions that I am looking for which are listed in a range called
"Opcos"

I think it's vbTextCompare I need to use but don't know where to start with
writing the code to do this. Could someone please help me with the code

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Find String within Cell

KAren,

Sub FindOpCos()

Dim myAM As Range
Dim myCell As Range

For Each myAM In Range("AM1", Range("AM65536").End(xlUp))
For Each myCell In Range("Opcos")
If InStr(1, myAM.Value, myCell.Value) 0 Then
Cells(myAM.Row, 2).Value = myCell.Value
GoTo Found:
End If
Next myCell
Found:
Next myAM

End Sub

HTH,
Bernie
MS Excel MVP


"Karen McKenzie" wrote in message
...
I have a spreadsheet which uses concatenated data as the basis for sumif
calculations looking at another spreadsheet. In separate columns however, I
want to be able to split out the concatenated data.

Column AM has my concatenated data as follows:

Glasgow Property Freehold
South Yorkshire Property Shorthold Lease
Edinburgh Other Telephone System

I want to be able to search in column AM, find the Region (Glasgow,
Edinburgh....) and return that region into column B of the same row. I have
approx 20 regions that I am looking for which are listed in a range called
"Opcos"

I think it's vbTextCompare I need to use but don't know where to start with
writing the code to do this. Could someone please help me with the code



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Find String within Cell

It runs but doesn't do what I want it to. Should I be replacing the "f" with
something?

"Karen McKenzie" wrote:

I have a spreadsheet which uses concatenated data as the basis for sumif
calculations looking at another spreadsheet. In separate columns however, I
want to be able to split out the concatenated data.

Column AM has my concatenated data as follows:

Glasgow Property Freehold
South Yorkshire Property Shorthold Lease
Edinburgh Other Telephone System

I want to be able to search in column AM, find the Region (Glasgow,
Edinburgh....) and return that region into column B of the same row. I have
approx 20 regions that I am looking for which are listed in a range called
"Opcos"

I think it's vbTextCompare I need to use but don't know where to start with
writing the code to do this. Could someone please help me with the code

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Find String within Cell

ry changing this line

from:
Cells(cell.Row, "B") = cell
to:
Cells(c.Row, "B") = cell

"Karen McKenzie" wrote:

It runs but doesn't do what I want it to. Should I be replacing the "f" with
something?

"Karen McKenzie" wrote:

I have a spreadsheet which uses concatenated data as the basis for sumif
calculations looking at another spreadsheet. In separate columns however, I
want to be able to split out the concatenated data.

Column AM has my concatenated data as follows:

Glasgow Property Freehold
South Yorkshire Property Shorthold Lease
Edinburgh Other Telephone System

I want to be able to search in column AM, find the Region (Glasgow,
Edinburgh....) and return that region into column B of the same row. I have
approx 20 regions that I am looking for which are listed in a range called
"Opcos"

I think it's vbTextCompare I need to use but don't know where to start with
writing the code to do this. Could someone please help me with the code



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Find String within Cell

Karen,

Joel's method is also written to only find each Opcos value once.... I think mine will do what you
want.

HTH,
Bernie
MS Excel MVP


"Karen McKenzie" wrote in message
...
It runs but doesn't do what I want it to. Should I be replacing the "f" with
something?

"Karen McKenzie" wrote:

I have a spreadsheet which uses concatenated data as the basis for sumif
calculations looking at another spreadsheet. In separate columns however, I
want to be able to split out the concatenated data.

Column AM has my concatenated data as follows:

Glasgow Property Freehold
South Yorkshire Property Shorthold Lease
Edinburgh Other Telephone System

I want to be able to search in column AM, find the Region (Glasgow,
Edinburgh....) and return that region into column B of the same row. I have
approx 20 regions that I am looking for which are listed in a range called
"Opcos"

I think it's vbTextCompare I need to use but don't know where to start with
writing the code to do this. Could someone please help me with the code



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
How can I find a value from one cell in a char string in another? tiredazdaddy Excel Worksheet Functions 2 November 20th 08 05:40 PM
FIND / SEARCH text compare cell to string in 3rd cell nastech Excel Discussion (Misc queries) 0 October 29th 07 02:51 AM
Find a specific string in a cell loren.pottinger Excel Programming 3 August 22nd 06 05:10 PM
Find a String in a Cell jerry chapman[_2_] Excel Programming 1 February 5th 05 04:44 AM
Possible? find string and put in next cell... excelnewbie Excel Programming 8 October 15th 03 08:46 PM


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