Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Search Column then Paste Data at end of Row?

Hi,
I am going nowhere quick searching for this, so hopefully someone can
help me.

I have a sheet with "x" number of rows of data. I would like to search

the second column for a specific string. Each time the string is
found, I need to paste the value of variable "var1" and "var2" into
column Q and R of that row. I would also like to know how many times
the string was found at paste value into the first column of that row.


I'm sure I could use a For loop to do this, but the data sheet can be
very long and I was wondering if there was a better way to do this with

the ".find()" or ".advancedfilter()" functions.


Thanks,
Logan

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 791
Default Search Column then Paste Data at end of Row?

You can try setting all of the cells containing the strings to be found in a
range using something like this:

Lastrow= Range("P65536").end(xlup).row
set Rng = Range("P1:P" & Lastrow)
Then loop through each occurrence comparing it to what is in your Column A
for example, and if found use the cell.offset functionality to place the var1
or var2 value. During the same loop you can insert a counter x=x+1 or
something similar. And when it gets out of the loop reset the x value to 0,
taking first the current value of x and placing it into the cell of your
choice.

" wrote:

Hi,
I am going nowhere quick searching for this, so hopefully someone can
help me.

I have a sheet with "x" number of rows of data. I would like to search

the second column for a specific string. Each time the string is
found, I need to paste the value of variable "var1" and "var2" into
column Q and R of that row. I would also like to know how many times
the string was found at paste value into the first column of that row.


I'm sure I could use a For loop to do this, but the data sheet can be
very long and I was wondering if there was a better way to do this with

the ".find()" or ".advancedfilter()" functions.


Thanks,
Logan


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Search Column then Paste Data at end of Row?

You could loop through each find until it wrapped to the top:

Sub Macro2()
Dim intFirstHit As Integer

'you can change this range to be what you want
With Range("A1:A50")
.Select
'find first hit
.Find(What:="b", After:=ActiveCell, LookIn:=xlFormulas, LookAt
_
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False).Activate
'mark first hit
intFirstHit = ActiveCell.Row
Range("Q" & ActiveCell.Row).Value = var1
Range("R" & ActiveCell.Row).Value = var2
Range("A1:A50").FindNext(After:=ActiveCell).Activa te
'do until you wrap around to the top of the selection
Do While ActiveCell.Row intFirstHit
Range("Q" & ActiveCell.Row).Value = var1
Range("R" & ActiveCell.Row).Value = var2
'find each other instance
.FindNext(After:=ActiveCell).Activate
Loop
End With
End Sub

I didn't understand exactly what you wanted with the second request.
Are you looking to keep a running tally of how many times you found the
string you were looking for or were you looking to see how many times a
single string appeared in a cell?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Search Column then Paste Data at end of Row?

Thanks. That looks like it should work. Except I don't know what the
range is. I will just have a variable telling me how many rows are in
the sheet.

I would like a running tally of how many times the string was found.
And paste that in column 1 of each found instance or maybe just column
1 of the first hit.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Search Column then Paste Data at end of Row?

You could just include a counter variable in the loop and put it in the
column. Something like this:

Sub Macro2()
Dim intFirstHit As Integer
Dim i as double
'you can change this range to be what you want
With Range("A1:A50")
.Select
'find first hit
.Find(What:="b", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False).Activate
'mark first hit
intFirstHit = ActiveCell.Row
i = 1
Range("Q" & ActiveCell.Row).Value = var1
Range("R" & ActiveCell.Row).Value = var2
Range("S" & ActiveCell.Row).Value = i
.FindNext(After:=ActiveCell).Activate
'do until you wrap around to the top of the selection
Do While ActiveCell.Row intFirstHit
i = i + 1
Range("Q" & ActiveCell.Row).Value = var1
Range("R" & ActiveCell.Row).Value = var2
Range("S" & ActiveCell.Row).Value = i
'find each other instance
.FindNext(After:=ActiveCell).Activate
Loop
End With
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Search Column then Paste Data at end of Row?

Here is a more elegant way to do this code that I found at ozgrid:

http://www.ozgrid.com/VBA/find-method.htm

Dim lCount As Long
Dim rFoundCell As Range

Set rFoundCell = Range("A1")

For lCount = 1 To WorksheetFunction.CountIf(Columns(1), "Cat")
Set rFoundCell = Columns(1).Find(What:="Cat",
After:=rFoundCell, _
LookIn:=xlValues, LookAt:=xlPart,
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)

With rFoundCell
.ClearComments
.AddComment Text:="Cat lives here"
End With

Next lCount
End Sub

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Search Column then Paste Data at end of Row?

Thanks for all the help guys. I tried Brian's suggestion before I left
work, but I was getting an error. I'll try again on Monday and let you
know how it works.

BTW, I saw the tip at ozgrid, but had no idea how to use that and add
the data at the end of the row.


Also, dmthornton gave me this solution:

Quote:
I'm glad I saw your posting. I never thought of using the
advancedfilter
function for something like this, but I think it could save time. I
played
arround with it and came up with this. I think if you tweek it, it
should
work.

Selection.AutoFilter Field:=2, Criteria1:="FindThisString"
Dim lngCount As Long
lngCount = Range("B2",
Range("B65536").End(xlUp)).SpecialCells(xlCellType Visible).Count
'lngCount
will give you the totoal number of rows


'Do for only the visible cells
For Each c In Range("B2",
Range("B65536").End(xlUp)).SpecialCells(xlCellType Visible)
c.Offset(0, 15) = "new value"
c.Offset(0, 16) = "new value"
Next

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 104
Default Search Column then Paste Data at end of Row?

Logan,
Is the Second Column, Column B? and how var1 and var2 determined? Also
what determines the value your searching in column 2. The rest is pretty
much straight by using Find, and Find Next method. Posted me back and see if
I can give you a hand...

Rick (Fbks, AK)


wrote in message
oups.com...
Hi,
I am going nowhere quick searching for this, so hopefully someone can
help me.

I have a sheet with "x" number of rows of data. I would like to search

the second column for a specific string. Each time the string is
found, I need to paste the value of variable "var1" and "var2" into
column Q and R of that row. I would also like to know how many times
the string was found at paste value into the first column of that row.


I'm sure I could use a For loop to do this, but the data sheet can be
very long and I was wondering if there was a better way to do this with

the ".find()" or ".advancedfilter()" functions.


Thanks,
Logan



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 end of data in column [email protected] Excel Worksheet Functions 3 May 12th 07 04:26 PM
Based on a condition in one column, search for a year in another column, and display data from another column in the same row look [email protected] Excel Discussion (Misc queries) 1 December 27th 06 05:47 PM
Need to Search Column then Paste Data at end of Row? Advanced Filter? [email protected] Excel Programming 1 May 13th 06 12:11 AM
search a column for a specific piece of data using vba dave91 Excel Programming 1 July 23rd 05 05:56 PM
search column for a specific piece of data using vba dave91 Excel Programming 2 July 23rd 05 02:24 PM


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