Do an action until find a word in a column

kfilippo

New Member
Joined
Jan 9, 2018
Messages
11
Hello,

What is the command to do an action until I find a specific work in my column A? And once this word is found, stop the action.

Thank you
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,197
Maybe the command is called a loop using VBA, but maybe also you can use a formula depending on what it is you are doing. More info from you can help people here to help you with a solution.
 

kfilippo

New Member
Joined
Jan 9, 2018
Messages
11
Maybe the command is called a loop using VBA, but maybe also you can use a formula depending on what it is you are doing. More info from you can help people here to help you with a solution.
I need to paste a certain text in the rows of column H until the word "account" appears in column A.
For ex, if the word "account" appears in cell A6, I need to paste my text on H1 to H5 cells.
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,197
This can be done with a formula if by paste you mean just put the word "account" into (for example) H1:H5.

But if you...
• need to append the existing values that are each in H1:H5 with "account",
• or if by paste you are first copying it from another outside source,
• or you don't want all those formulas in column H,
...then VBA would be the better way to go. What's your preference?
 

kfilippo

New Member
Joined
Jan 9, 2018
Messages
11
This can be done with a formula if by paste you mean just put the word "account" into (for example) H1:H5.

But if you...
• need to append the existing values that are each in H1:H5 with "account",
• or if by paste you are first copying it from another outside source,
• or you don't want all those formulas in column H,
...then VBA would be the better way to go. What's your preference?
Yes, I need to append the existing values that are each in H1:H5 with "account". Also, I´m copying it from another outside source.

Thanks
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,197
Assuming by append, you want account to precede the existing data,

Code:
Sub Test1()
Dim keyVal$, vRow As Variant
keyVal = "account"
vRow = Application.Match(keyVal, Columns(1), 0)
If IsError(vRow) Then
MsgBox keyVal & " not found", 64, "No row reference"
Else
Dim cell As Range
Application.ScreenUpdating = False
For Each cell In Range(Cells(1, 8), Cells(vRow - 1, 8))
cell.Value = keyVal & " " & cell.Value
Next cell
Application.ScreenUpdating = True
End If
End Sub
 

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,197
If you have different text at any given time on your clipboard, this is what you would need for that:

Code:
Sub Test2()
Dim keyVal$, vRow As Variant
keyVal = "account"
vRow = Application.Match(keyVal, Columns(1), 0)
If IsError(vRow) Then
MsgBox keyVal & " not found", 64, "No row reference"
Else
Dim objAppend As MsForms.DataObject, strAppend$, cell As Range
Set objAppend = New MsForms.DataObject
objAppend.GetFromClipboard
On Error Resume Next
strAppend = objAppend.GetText(1)
If Err.Number <> 0 Then
Err.Clear
MsgBox "No text is on the clipboard.", 48, "Nothing to append"
Exit Sub
End If
Application.ScreenUpdating = False
For Each cell In Range(Cells(1, 8), Cells(vRow - 1, 8))
cell.Value = strAppend & " " & cell.Value
Next cell
Set objAppend = Nothing
Application.ScreenUpdating = True
End If
End Sub
 

Forum statistics

Threads
1,082,177
Messages
5,363,591
Members
400,753
Latest member
Lizanz

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top