PC Review


Reply
Thread Tools Rate Thread

Copy info between 2 specific words

 
 
Wolfwalker721
Guest
Posts: n/a
 
      14th Aug 2009
Hi,

I have been trying to use a macro to find a word in a column, then find the
next instance of that word in the same colum, Then copy the information
between+4 colums to another sheet, in the first blank column, in the same
workbook.

I hope this makes sence. I can generaly grasp basic macro commands but I am
in over my head on this one. Any help would be appriciated.

THANKS in advance
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      14th Aug 2009
Change the sheet names and the start and end columns as required.

Sub GetData()

Set Sourcesht = Sheets("Sheet1")
Set DestSht = Sheets("Sheet2")

StartCol = "C"
EndCol = "G"
SearchWord = "Joel"


RowCount = 1
StartRow = 0
With Sourcesht
LastRow1 = .Range(StartCol & Rows.Count).End(xlUp).Row
Found = False
For RowCount = 1 To LastRow1
Select Case Found

Case False:
If .Range(StartCol & RowCount) = SearchWord Then
Found = True
StartRow = RowCount
End If
Case True
If .Range(StartCol & RowCount) = SearchWord Then
Set CopyRange = _
.Range(StartCol & StartRow & ":" & _
EndCol & RowCount)

With DestSht
LastRow2 = .Range("A" & Rows.Count).End(xlUp).Row
NewRow = LastRow2 + 1
CopyRange.Copy _
Destination:=.Range("A" & NewRow)
End With
Found = False
End If
End Select
Next RowCount
End With
End Sub



"Wolfwalker721" wrote:

> Hi,
>
> I have been trying to use a macro to find a word in a column, then find the
> next instance of that word in the same colum, Then copy the information
> between+4 colums to another sheet, in the first blank column, in the same
> workbook.
>
> I hope this makes sence. I can generaly grasp basic macro commands but I am
> in over my head on this one. Any help would be appriciated.
>
> THANKS in advance

 
Reply With Quote
 
Wolfwalker721
Guest
Posts: n/a
 
      14th Aug 2009
This works great! Only I am trying to copy the info in the first blank column
instead of the first blank row. =)

Thanks so much for yout time!

"Joel" wrote:

> Change the sheet names and the start and end columns as required.
>
> Sub GetData()
>
> Set Sourcesht = Sheets("Sheet1")
> Set DestSht = Sheets("Sheet2")
>
> StartCol = "C"
> EndCol = "G"
> SearchWord = "Joel"
>
>
> RowCount = 1
> StartRow = 0
> With Sourcesht
> LastRow1 = .Range(StartCol & Rows.Count).End(xlUp).Row
> Found = False
> For RowCount = 1 To LastRow1
> Select Case Found
>
> Case False:
> If .Range(StartCol & RowCount) = SearchWord Then
> Found = True
> StartRow = RowCount
> End If
> Case True
> If .Range(StartCol & RowCount) = SearchWord Then
> Set CopyRange = _
> .Range(StartCol & StartRow & ":" & _
> EndCol & RowCount)
>
> With DestSht
> LastRow2 = .Range("A" & Rows.Count).End(xlUp).Row
> NewRow = LastRow2 + 1
> CopyRange.Copy _
> Destination:=.Range("A" & NewRow)
> End With
> Found = False
> End If
> End Select
> Next RowCount
> End With
> End Sub
>
>
>
> "Wolfwalker721" wrote:
>
> > Hi,
> >
> > I have been trying to use a macro to find a word in a column, then find the
> > next instance of that word in the same colum, Then copy the information
> > between+4 colums to another sheet, in the first blank column, in the same
> > workbook.
> >
> > I hope this makes sence. I can generaly grasp basic macro commands but I am
> > in over my head on this one. Any help would be appriciated.
> >
> > THANKS in advance

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      14th Aug 2009
This is similar code for columns. I'm not sure if you are looking a one row
or moving down the worksheet and looking at all rows. You need to use CELLS
instead of RANGE when using columns.

"Wolfwalker721" wrote:

> This works great! Only I am trying to copy the info in the first blank column
> instead of the first blank row. =)
>
> Thanks so much for yout time!
>
> "Joel" wrote:
>
> > Change the sheet names and the start and end columns as required.
> >
> > Sub GetData()
> >
> > Set Sourcesht = Sheets("Sheet1")
> > Set DestSht = Sheets("Sheet2")
> >
> > StartCol = "C"
> > EndCol = "G"
> > SearchWord = "Joel"
> >
> >
> > RowCount = 1
> > StartRow = 0
> > With Sourcesht
> > LastRow1 = .Range(StartCol & Rows.Count).End(xlUp).Row
> > Found = False
> > For RowCount = 1 To LastRow1
> > Select Case Found
> >
> > Case False:
> > If .Range(StartCol & RowCount) = SearchWord Then
> > Found = True
> > StartRow = RowCount
> > End If
> > Case True
> > If .Range(StartCol & RowCount) = SearchWord Then
> > Set CopyRange = _
> > .Range(StartCol & StartRow & ":" & _
> > EndCol & RowCount)
> >
> > With DestSht
> > LastRow2 = .Range("A" & Rows.Count).End(xlUp).Row
> > NewRow = LastRow2 + 1
> > CopyRange.Copy _
> > Destination:=.Range("A" & NewRow)
> > End With
> > Found = False
> > End If
> > End Select
> > Next RowCount
> > End With
> > End Sub
> >
> >
> >
> > "Wolfwalker721" wrote:
> >
> > > Hi,
> > >
> > > I have been trying to use a macro to find a word in a column, then find the
> > > next instance of that word in the same colum, Then copy the information
> > > between+4 colums to another sheet, in the first blank column, in the same
> > > workbook.
> > >
> > > I hope this makes sence. I can generaly grasp basic macro commands but I am
> > > in over my head on this one. Any help would be appriciated.
> > >
> > > THANKS in advance

 
Reply With Quote
 
Wolfwalker721
Guest
Posts: n/a
 
      14th Aug 2009
Thanks this is a big help, to clarify

I am trying to search the entire A column where the word "Done" appears many
times, then copy Column A-D between each instance of the word "Done" and
paste it to another sheet in the first empty colum.

"Joel" wrote:

> This is similar code for columns. I'm not sure if you are looking a one row
> or moving down the worksheet and looking at all rows. You need to use CELLS
> instead of RANGE when using columns.
>
> "Wolfwalker721" wrote:
>
> > This works great! Only I am trying to copy the info in the first blank column
> > instead of the first blank row. =)
> >
> > Thanks so much for yout time!
> >
> > "Joel" wrote:
> >
> > > Change the sheet names and the start and end columns as required.
> > >
> > > Sub GetData()
> > >
> > > Set Sourcesht = Sheets("Sheet1")
> > > Set DestSht = Sheets("Sheet2")
> > >
> > > StartCol = "C"
> > > EndCol = "G"
> > > SearchWord = "Joel"
> > >
> > >
> > > RowCount = 1
> > > StartRow = 0
> > > With Sourcesht
> > > LastRow1 = .Range(StartCol & Rows.Count).End(xlUp).Row
> > > Found = False
> > > For RowCount = 1 To LastRow1
> > > Select Case Found
> > >
> > > Case False:
> > > If .Range(StartCol & RowCount) = SearchWord Then
> > > Found = True
> > > StartRow = RowCount
> > > End If
> > > Case True
> > > If .Range(StartCol & RowCount) = SearchWord Then
> > > Set CopyRange = _
> > > .Range(StartCol & StartRow & ":" & _
> > > EndCol & RowCount)
> > >
> > > With DestSht
> > > LastRow2 = .Range("A" & Rows.Count).End(xlUp).Row
> > > NewRow = LastRow2 + 1
> > > CopyRange.Copy _
> > > Destination:=.Range("A" & NewRow)
> > > End With
> > > Found = False
> > > End If
> > > End Select
> > > Next RowCount
> > > End With
> > > End Sub
> > >
> > >
> > >
> > > "Wolfwalker721" wrote:
> > >
> > > > Hi,
> > > >
> > > > I have been trying to use a macro to find a word in a column, then find the
> > > > next instance of that word in the same colum, Then copy the information
> > > > between+4 colums to another sheet, in the first blank column, in the same
> > > > workbook.
> > > >
> > > > I hope this makes sence. I can generaly grasp basic macro commands but I am
> > > > in over my head on this one. Any help would be appriciated.
> > > >
> > > > THANKS in advance

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      14th Aug 2009
The 1st macro was closer to what you wanted than the 2nd. If ther are more
than 256/4 setctions that need to be copied then you are goig to go past
column 256 and an error will occur. the macro could be easily mdoifed when
256 column (IV) is reached the code will wrap back to column A.

Change sheet names as required.

Sub GetData()

Set Sourcesht = Sheets("Sheet1")
Set DestSht = Sheets("Sheet2")

StartCol = "A"
EndCol = "D"
SearchWord = "Done"


RowCount = 1
StartRow = 0
With Sourcesht
LastRow = .Range(StartCol & Rows.Count).End(xlUp).Row
Found = False
For RowCount = 1 To LastRow
Select Case Found
Case False:
If .Range(StartCol & RowCount) = SearchWord Then
Found = True
StartRow = RowCount
End If
Case True
If .Range(StartCol & RowCount) = SearchWord Then
Set CopyRange = _
.Range(StartCol & StartRow & ":" & _
EndCol & RowCount)

With DestSht
LastCol = .Cells(1, Columns.Count).End(xlToLeft).Row
NewCol = LastCol + 1
CopyRange.Copy _
Destination:=.Cells(1, NewCol)
End With
Found = False
End If
End Select
Next RowCount
End With
End Sub






"Wolfwalker721" wrote:

> Thanks this is a big help, to clarify
>
> I am trying to search the entire A column where the word "Done" appears many
> times, then copy Column A-D between each instance of the word "Done" and
> paste it to another sheet in the first empty colum.
>
> "Joel" wrote:
>
> > This is similar code for columns. I'm not sure if you are looking a one row
> > or moving down the worksheet and looking at all rows. You need to use CELLS
> > instead of RANGE when using columns.
> >
> > "Wolfwalker721" wrote:
> >
> > > This works great! Only I am trying to copy the info in the first blank column
> > > instead of the first blank row. =)
> > >
> > > Thanks so much for yout time!
> > >
> > > "Joel" wrote:
> > >
> > > > Change the sheet names and the start and end columns as required.
> > > >
> > > > Sub GetData()
> > > >
> > > > Set Sourcesht = Sheets("Sheet1")
> > > > Set DestSht = Sheets("Sheet2")
> > > >
> > > > StartCol = "C"
> > > > EndCol = "G"
> > > > SearchWord = "Joel"
> > > >
> > > >
> > > > RowCount = 1
> > > > StartRow = 0
> > > > With Sourcesht
> > > > LastRow1 = .Range(StartCol & Rows.Count).End(xlUp).Row
> > > > Found = False
> > > > For RowCount = 1 To LastRow1
> > > > Select Case Found
> > > >
> > > > Case False:
> > > > If .Range(StartCol & RowCount) = SearchWord Then
> > > > Found = True
> > > > StartRow = RowCount
> > > > End If
> > > > Case True
> > > > If .Range(StartCol & RowCount) = SearchWord Then
> > > > Set CopyRange = _
> > > > .Range(StartCol & StartRow & ":" & _
> > > > EndCol & RowCount)
> > > >
> > > > With DestSht
> > > > LastRow2 = .Range("A" & Rows.Count).End(xlUp).Row
> > > > NewRow = LastRow2 + 1
> > > > CopyRange.Copy _
> > > > Destination:=.Range("A" & NewRow)
> > > > End With
> > > > Found = False
> > > > End If
> > > > End Select
> > > > Next RowCount
> > > > End With
> > > > End Sub
> > > >
> > > >
> > > >
> > > > "Wolfwalker721" wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > > I have been trying to use a macro to find a word in a column, then find the
> > > > > next instance of that word in the same colum, Then copy the information
> > > > > between+4 colums to another sheet, in the first blank column, in the same
> > > > > workbook.
> > > > >
> > > > > I hope this makes sence. I can generaly grasp basic macro commands but I am
> > > > > in over my head on this one. Any help would be appriciated.
> > > > >
> > > > > THANKS in advance

 
Reply With Quote
 
Wolfwalker721
Guest
Posts: n/a
 
      14th Aug 2009
This is GREAT! THANKS

"Joel" wrote:

> The 1st macro was closer to what you wanted than the 2nd. If ther are more
> than 256/4 setctions that need to be copied then you are goig to go past
> column 256 and an error will occur. the macro could be easily mdoifed when
> 256 column (IV) is reached the code will wrap back to column A.
>
> Change sheet names as required.
>
> Sub GetData()
>
> Set Sourcesht = Sheets("Sheet1")
> Set DestSht = Sheets("Sheet2")
>
> StartCol = "A"
> EndCol = "D"
> SearchWord = "Done"
>
>
> RowCount = 1
> StartRow = 0
> With Sourcesht
> LastRow = .Range(StartCol & Rows.Count).End(xlUp).Row
> Found = False
> For RowCount = 1 To LastRow
> Select Case Found
> Case False:
> If .Range(StartCol & RowCount) = SearchWord Then
> Found = True
> StartRow = RowCount
> End If
> Case True
> If .Range(StartCol & RowCount) = SearchWord Then
> Set CopyRange = _
> .Range(StartCol & StartRow & ":" & _
> EndCol & RowCount)
>
> With DestSht
> LastCol = .Cells(1, Columns.Count).End(xlToLeft).Row
> NewCol = LastCol + 1
> CopyRange.Copy _
> Destination:=.Cells(1, NewCol)
> End With
> Found = False
> End If
> End Select
> Next RowCount
> End With
> End Sub
>
>
>
>
>
>
> "Wolfwalker721" wrote:
>
> > Thanks this is a big help, to clarify
> >
> > I am trying to search the entire A column where the word "Done" appears many
> > times, then copy Column A-D between each instance of the word "Done" and
> > paste it to another sheet in the first empty colum.
> >
> > "Joel" wrote:
> >
> > > This is similar code for columns. I'm not sure if you are looking a one row
> > > or moving down the worksheet and looking at all rows. You need to use CELLS
> > > instead of RANGE when using columns.
> > >
> > > "Wolfwalker721" wrote:
> > >
> > > > This works great! Only I am trying to copy the info in the first blank column
> > > > instead of the first blank row. =)
> > > >
> > > > Thanks so much for yout time!
> > > >
> > > > "Joel" wrote:
> > > >
> > > > > Change the sheet names and the start and end columns as required.
> > > > >
> > > > > Sub GetData()
> > > > >
> > > > > Set Sourcesht = Sheets("Sheet1")
> > > > > Set DestSht = Sheets("Sheet2")
> > > > >
> > > > > StartCol = "C"
> > > > > EndCol = "G"
> > > > > SearchWord = "Joel"
> > > > >
> > > > >
> > > > > RowCount = 1
> > > > > StartRow = 0
> > > > > With Sourcesht
> > > > > LastRow1 = .Range(StartCol & Rows.Count).End(xlUp).Row
> > > > > Found = False
> > > > > For RowCount = 1 To LastRow1
> > > > > Select Case Found
> > > > >
> > > > > Case False:
> > > > > If .Range(StartCol & RowCount) = SearchWord Then
> > > > > Found = True
> > > > > StartRow = RowCount
> > > > > End If
> > > > > Case True
> > > > > If .Range(StartCol & RowCount) = SearchWord Then
> > > > > Set CopyRange = _
> > > > > .Range(StartCol & StartRow & ":" & _
> > > > > EndCol & RowCount)
> > > > >
> > > > > With DestSht
> > > > > LastRow2 = .Range("A" & Rows.Count).End(xlUp).Row
> > > > > NewRow = LastRow2 + 1
> > > > > CopyRange.Copy _
> > > > > Destination:=.Range("A" & NewRow)
> > > > > End With
> > > > > Found = False
> > > > > End If
> > > > > End Select
> > > > > Next RowCount
> > > > > End With
> > > > > End Sub
> > > > >
> > > > >
> > > > >
> > > > > "Wolfwalker721" wrote:
> > > > >
> > > > > > Hi,
> > > > > >
> > > > > > I have been trying to use a macro to find a word in a column, then find the
> > > > > > next instance of that word in the same colum, Then copy the information
> > > > > > between+4 colums to another sheet, in the first blank column, in the same
> > > > > > workbook.
> > > > > >
> > > > > > I hope this makes sence. I can generaly grasp basic macro commands but I am
> > > > > > in over my head on this one. Any help would be appriciated.
> > > > > >
> > > > > > THANKS in advance

 
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
Excel VBA - copy csv info to specific cells Vince Bowman Microsoft Excel Programming 4 23rd Dec 2009 01:10 AM
how can i copy specific words from a paragraph at once =?Utf-8?B?d29yZCBxdWVzdGlvbg==?= Microsoft Word Document Management 1 7th Oct 2007 06:25 AM
Rule - Specific Address OR Specific Words In Subject =?Utf-8?B?RmluZE15RGF0ZXMuY29t?= Microsoft Outlook Discussion 1 4th Jul 2007 02:29 PM
counting occurrence of specific words in another group of words kh@horsemanship101.com Microsoft Excel Programming 0 5th Aug 2006 03:43 AM
search for a specific word and copy the word and the preceeding words until a comma DHANANJAY Microsoft Excel Programming 12 31st Dec 2005 12:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:22 AM.