LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Create a Macro to Insert a number into a column based on crite

Column B is the offset of one column from A. Here is the line that does that.
rngFoundAll.Offset(0, 1).Value = strValue
What this code does is it seaches Column A for all instances (rngFoundAll)
of "016" or whatever you set as the second argument (strWhat). It then places
"234" (strValue) one column to the right of the items that it found.

It works with multiple instances and is very efficient in how it searches...
--
HTH...

Jim Thomlinson


" wrote:

I proably have overlooked it, but where is column B referenced. I want
to insert 234 on every line (row) in column B where column A's line
(row) equals 016. This occurs multiple times in the worksheet, not
just one instance. If it does that, please forgive me. Thanks again



Jim Thomlinson wrote:
Here is one way using find...

Public Sub AddStuff()
Call FindStuff(Columns("A"), "016", "234")
Call FindStuff(Columns("A"), "This", "That")
End Sub

Private Sub FindStuff(ByVal rngToSearch As Range, ByVal strWhat As String, _
ByVal strValue As String)
Dim rngFound As Range
Dim rngFoundAll As Range
Dim strFirstAddress As String

Set rngFound = rngToSearch.Find(What:=strWhat, _
LookAt:=xlWhole, _
LookIn:=xlValues, _
MatchCase:=False)
If Not rngFound Is Nothing Then
strFirstAddress = rngFound.Address
Set rngFoundAll = rngFound
Do
Set rngFoundAll = Union(rngFound, rngFoundAll)
Set rngFound = rngToSearch.FindNext(rngFound)
Loop Until rngFound.Address = strFirstAddress
rngFoundAll.Offset(0, 1).Value = strValue
End If
End Sub
--
HTH...

Jim Thomlinson


" wrote:

Hello,

I so used to working with Access that I'm having trouble trying how to
write this simple macro I need:

I want to create a macro that says if column A has "016" then insert
"234" into Column B. I need to do mulitple of these, so that was just
an example. I'm in a time crunch at work. Thanks a million in
advance !!!!!







 
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
Add a number sequence based on criteria in another column DanaK Excel Worksheet Functions 3 September 26th 09 07:13 AM
insert rows based on criteria MP Excel Discussion (Misc queries) 3 December 4th 08 02:19 PM
insert rows based on criteria MP Excel Discussion (Misc queries) 0 December 3rd 08 06:36 PM
Insert text from another workbook based on criteria Tacrier Excel Worksheet Functions 4 April 9th 08 11:01 PM
Insert Criteria Based on Current Month Mark Jackson Excel Worksheet Functions 3 May 19th 06 03:16 PM


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