Solved

Loop through range and update four worksheets from old value to new

Posted on 2011-03-08
4
222 Views
Last Modified: 2012-05-11
I have a workbook that creates four worksheets with data that will be uploaded into an ACCESS database. The worksheet names are ("chrts", "Top10", "gics", "Ctry").   However, due to user changes, some of the row headers needs to be changed.  That is, say a row is labled "Market Cap" in the source data, but needs to be changed to "Market Capilization" on the upload worksheet.  I have a two-column range ("RowHeaderChanges") that has the OldRowHeader column and a NewRowHeader column which holds this old/new information.  So, how do I loop through this range and change the values?  I need locate in column A on each worksheet the value "Market Cap" and change it to "Market Caplization", and then go to the next old value in the range, loop through the worksheets checking for this value and update to the new value if it is found.  All this must be done in VBA.
Public Sub UpdateRowHeaders()
Dim varGroup As Variant

For Each varGroup In Array("chrts", "Top10", "gics", "Ctry")
    

Next

End Sub

Open in new window

0
Comment
Question by:ssmith94015
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 35072559
Try this. I would not be able to try it unless you provide a sample workbook.

Saqib



Sub UpdateRowHeaders()

For Each shname In Array("chrts", "Top10", "gics", "Ctry")
Set ws = Worksheets(shname)
For Each cel In Intersect(ws.UsedRange, Range("A:A"))
If cel.Value <> "" Then cel.Value = WorksheetFunction.VLookup(cel.Value, Range("rowheaderchanges"), 2, 0)
Next cel
Next shname

End Sub
0
 

Author Comment

by:ssmith94015
ID: 35074429
Cannot use the Used range as there are multiple area on the worksheet that are used by code.  I need to restrict the range to the named range.  The intersect won't work for this scenario as the range does not interesect.  I willl need to clean up the workbook before I can post as this is confidential data.  I was thinking about this and was wondering if filling an array with the data adn then using the array to compare the upload to.  I have to work on another issue today so will not be able to get back to this until tomorrow.
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 35076436
I shall wait for the sample file.
0
 

Author Closing Comment

by:ssmith94015
ID: 35096636
I found an easiser way to answer the original question, this this answer did solve another problem I came across.  Thank you.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question