Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default VBA to select the cells next to the result of a find & combine the

I've got data that always appears in the two cell immediately to the right of
a cell that contains "Case:" that I'd like to select. In other words if
"Case:" appears in C33, then the two cells I want to select are in D33 and
E33. The trouble is the row isn't always the same from time to time (the
sheet is as a result of imported text). I can do a find to locate the cell
with "Case:" but then what do I do? This seems like it should be so simple
but I'm coming up blank.

Once I select the contents of those two cells, I'd like to combine the
contents of the two cells into a third cell. In other words if the contents
of the cell in D33 is "211" and the contents of the cell in E33 is "FEG" I'd
like to combine them into a third cell (say G4) which would have the value of
"211FEG" therefore. Again, it doesn't seem like it should be that difficult
but I'm struggling.

Your help would be greatly appreciated. Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default VBA to select the cells next to the result of a find & combine the

Try this:

Sub fndCase()
Dim c As Range
With Worksheets(1).UsedRange 'Change to actual
Set c = .Find("Case", After:=Range("A65535"), LookIn:=xlValues)
If Not c Is Nothing Then
fRng = c.Address
Range("G4") = Range(fRng).Offset(0, 1).Value & _
Range(fRng).Offset(0, 2).Value
End If
End With
End Sub

"ArielZusya" wrote:

I've got data that always appears in the two cell immediately to the right of
a cell that contains "Case:" that I'd like to select. In other words if
"Case:" appears in C33, then the two cells I want to select are in D33 and
E33. The trouble is the row isn't always the same from time to time (the
sheet is as a result of imported text). I can do a find to locate the cell
with "Case:" but then what do I do? This seems like it should be so simple
but I'm coming up blank.

Once I select the contents of those two cells, I'd like to combine the
contents of the two cells into a third cell. In other words if the contents
of the cell in D33 is "211" and the contents of the cell in E33 is "FEG" I'd
like to combine them into a third cell (say G4) which would have the value of
"211FEG" therefore. Again, it doesn't seem like it should be that difficult
but I'm struggling.

Your help would be greatly appreciated. Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default VBA to select the cells next to the result of a find & combine

Forgot I was in a With statement. Put the dot before the Range ref.
so it won't jump to the active sheet and error out.

Sub fndCase()
Dim c As Range
With Worksheets(1).UsedRange 'Change to actual
Set c = .Find("Case", After:=Range("A65535"), LookIn:=xlValues)
If Not c Is Nothing Then
fRng = c.Address
.Range("G4") = .Range(fRng).Offset(0, 1).Value & _
..Range(fRng).Offset(0, 2).Value
End If
End With
End Sub



"JLGWhiz" wrote:

Try this:

Sub fndCase()
Dim c As Range
With Worksheets(1).UsedRange 'Change to actual
Set c = .Find("Case", After:=Range("A65535"), LookIn:=xlValues)
If Not c Is Nothing Then
fRng = c.Address
Range("G4") = Range(fRng).Offset(0, 1).Value & _
Range(fRng).Offset(0, 2).Value
End If
End With
End Sub

"ArielZusya" wrote:

I've got data that always appears in the two cell immediately to the right of
a cell that contains "Case:" that I'd like to select. In other words if
"Case:" appears in C33, then the two cells I want to select are in D33 and
E33. The trouble is the row isn't always the same from time to time (the
sheet is as a result of imported text). I can do a find to locate the cell
with "Case:" but then what do I do? This seems like it should be so simple
but I'm coming up blank.

Once I select the contents of those two cells, I'd like to combine the
contents of the two cells into a third cell. In other words if the contents
of the cell in D33 is "211" and the contents of the cell in E33 is "FEG" I'd
like to combine them into a third cell (say G4) which would have the value of
"211FEG" therefore. Again, it doesn't seem like it should be that difficult
but I'm struggling.

Your help would be greatly appreciated. Thanks!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default VBA to select the cells next to the result of a find & combine

Thanks for your quick reply. I'm not following your suggestion. I'm sure
I'm missing a step or something. I copied your code and put it in the spot
I'd need to do the find, select, combine, and paste but it didn't appear to
do anything. Is there more I'm supposed to do? I'm still lost. Thanks for
your continued help.

"JLGWhiz" wrote:

Try this:

Sub fndCase()
Dim c As Range
With Worksheets(1).UsedRange 'Change to actual
Set c = .Find("Case", After:=Range("A65535"), LookIn:=xlValues)
If Not c Is Nothing Then
fRng = c.Address
Range("G4") = Range(fRng).Offset(0, 1).Value & _
Range(fRng).Offset(0, 2).Value
End If
End With
End Sub

"ArielZusya" wrote:

I've got data that always appears in the two cell immediately to the right of
a cell that contains "Case:" that I'd like to select. In other words if
"Case:" appears in C33, then the two cells I want to select are in D33 and
E33. The trouble is the row isn't always the same from time to time (the
sheet is as a result of imported text). I can do a find to locate the cell
with "Case:" but then what do I do? This seems like it should be so simple
but I'm coming up blank.

Once I select the contents of those two cells, I'd like to combine the
contents of the two cells into a third cell. In other words if the contents
of the cell in D33 is "211" and the contents of the cell in E33 is "FEG" I'd
like to combine them into a third cell (say G4) which would have the value of
"211FEG" therefore. Again, it doesn't seem like it should be that difficult
but I'm struggling.

Your help would be greatly appreciated. Thanks!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default VBA to select the cells next to the result of a find & combine the

Code something like this should do what you want...

Dim R As Range
Dim Cel As Range
Dim LookUpRow As String
Dim LastUsedRow As Long
LookUpRow = "C"
LastUsedRow = Cells(Rows.Count, LookUpRow).End(xlUp).Row
For Each Cel In Range(LookUpRow & "1:" & LookUpRow & LastUsedRow)
If Cel.Value = "Case:" Then
Range("G4").Value = Cel.Offset(0, 1).Value & _
Cel.Offset(0, 2).Value
Exit For
End If
Next

Rick


"ArielZusya" wrote in message
...
I've got data that always appears in the two cell immediately to the right
of
a cell that contains "Case:" that I'd like to select. In other words if
"Case:" appears in C33, then the two cells I want to select are in D33 and
E33. The trouble is the row isn't always the same from time to time (the
sheet is as a result of imported text). I can do a find to locate the
cell
with "Case:" but then what do I do? This seems like it should be so
simple
but I'm coming up blank.

Once I select the contents of those two cells, I'd like to combine the
contents of the two cells into a third cell. In other words if the
contents
of the cell in D33 is "211" and the contents of the cell in E33 is "FEG"
I'd
like to combine them into a third cell (say G4) which would have the value
of
"211FEG" therefore. Again, it doesn't seem like it should be that
difficult
but I'm struggling.

Your help would be greatly appreciated. Thanks!




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
select dependent cells in the result cell GireeshaJ Excel Discussion (Misc queries) 0 February 11th 09 12:34 PM
select cells that are the result of a search john mcmichael Excel Discussion (Misc queries) 3 November 8th 06 09:26 PM
find and Select cells Richard Excel Discussion (Misc queries) 1 June 23rd 06 12:00 PM
find and select all cells with a alphabetic character Giz Excel Programming 2 August 31st 05 06:07 PM
find and select cells with a given value Giz Excel Programming 1 August 31st 05 04:21 PM


All times are GMT +1. The time now is 06:48 AM.

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"