Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default SEARCH & REPLACE MACRO

I have imported txt files into 18 workshets in an Excel file that need
to have the value in column E changed from text data to a number.
They're actually accout names that I want to have replaced with an
account number. The Macro should go through all of the sheets in the
Excel file (right now that's 18) and replace all occurences of
"PURCHASES" in column E with "51000", replace all occurences of
"ADVERTISING" in column E with "63100" and replace all occurences of
"ALBERT" in column D with "65010". This would get me started enough
that I think I could code the rest of the macro, I just need to know
how to get started. I would like this macro to be saved in my
Personl.xls file so I can use it on multiple worksheets, but at this
time I have all of these worksheets combiled as one in order to test
it on all of them to make sure it will work before I use it on my
"live" data that I will import into a client's accounting software.

If there's some help out there, it would be great.

Thanks. You're in my prayers.

Josh
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default SEARCH & REPLACE MACRO

Sub MakeReplacements()
dim varr as variant, varr1 as variant, i as long
Dim sh as Worksheet, varr2 as variant
varr = Array("advertising", "purchases","albert")
varr1 = Array(63100, 51000, 65010)
varr2 = Array(5,5,4)
For each sh in Worksheets
for i = lbound(varr) to ubound(varr)
Columns(varr2(i)).Replace What:=varr(i), Replacement:=varr1(i), _
LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False
Next i
Next sh
End Sub

--
Regards,
Tom Ogilvy



"Josh" wrote in message
om...
I have imported txt files into 18 workshets in an Excel file that need
to have the value in column E changed from text data to a number.
They're actually accout names that I want to have replaced with an
account number. The Macro should go through all of the sheets in the
Excel file (right now that's 18) and replace all occurences of
"PURCHASES" in column E with "51000", replace all occurences of
"ADVERTISING" in column E with "63100" and replace all occurences of
"ALBERT" in column D with "65010". This would get me started enough
that I think I could code the rest of the macro, I just need to know
how to get started. I would like this macro to be saved in my
Personl.xls file so I can use it on multiple worksheets, but at this
time I have all of these worksheets combiled as one in order to test
it on all of them to make sure it will work before I use it on my
"live" data that I will import into a client's accounting software.

If there's some help out there, it would be great.

Thanks. You're in my prayers.

Josh



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default SEARCH & REPLACE MACRO

I altered the macro a little because the assertion

"varr2 = Array(5,5,4)"

doesn't look to the 4th column and change the 5th column data. What I
have is this:

Sub AccountNameToNumber()
Dim varr As Variant, varr1 As Variant, i As Long
Dim sh As Worksheet, varr2 As Variant
varr = Array("advertising", "purchases", "bait", "insurance", "payroll
liabilities", "automobile expense", "rent")
varr1 = Array(63000, 51000, 51000, 65200, 65500, 65100, 64400)
varr2 = Array(5, 5, 5, 5, 5, 5, 5)
For Each sh In Worksheets
For i = LBound(varr) To UBound(varr)
Columns(varr2(i)).Replace What:=varr(i), Replacement:=varr1(i), _
LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False
Next i
Next sh
End Sub

and it is good at changing the data in the 5th column with the values
(account numbers)listed in the varr1 line. I sometimes need to look
at partial data in the 4th column to make a change the data in the 5th
column to values (account numbers). For instance, if the 4th column
reads "AMERICAN EXPRESS" I want to be able to look for the data
"express" and have the data in the 5th column change to a value
specified appropraitely. Any ideas?

Thanks for helping out,

Josh


"Tom Ogilvy" wrote in message ...
Sub MakeReplacements()
dim varr as variant, varr1 as variant, i as long
Dim sh as Worksheet, varr2 as variant
varr = Array("advertising", "purchases","albert")
varr1 = Array(63100, 51000, 65010)
varr2 = Array(5,5,4)
For each sh in Worksheets
for i = lbound(varr) to ubound(varr)
Columns(varr2(i)).Replace What:=varr(i), Replacement:=varr1(i), _
LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False
Next i
Next sh
End Sub

--
Regards,
Tom Ogilvy



"Josh" wrote in message
om...
I have imported txt files into 18 workshets in an Excel file that need
to have the value in column E changed from text data to a number.
They're actually accout names that I want to have replaced with an
account number. The Macro should go through all of the sheets in the
Excel file (right now that's 18) and replace all occurences of
"PURCHASES" in column E with "51000", replace all occurences of
"ADVERTISING" in column E with "63100" and replace all occurences of
"ALBERT" in column D with "65010". This would get me started enough
that I think I could code the rest of the macro, I just need to know
how to get started. I would like this macro to be saved in my
Personl.xls file so I can use it on multiple worksheets, but at this
time I have all of these worksheets combiled as one in order to test
it on all of them to make sure it will work before I use it on my
"live" data that I will import into a client's accounting software.

If there's some help out there, it would be great.

Thanks. You're in my prayers.

Josh

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
Macro Search and Replace [email protected] Excel Discussion (Misc queries) 2 September 23rd 08 01:13 PM
macro to search and replace with offset Tim Excel Discussion (Misc queries) 5 December 11th 04 09:30 PM
Search and Replace Eric[_6_] Excel Programming 3 July 13th 04 09:44 AM
Macro to search a column for a specific word and replace with wendy Excel Programming 5 January 19th 04 05:41 PM
Macro search replace question WDP[_2_] Excel Programming 1 August 28th 03 06:18 AM


All times are GMT +1. The time now is 01:40 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"