Solved

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

Posted on 2011-03-08
4
217 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
  • 2
  • 2
4 Comments
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
I shall wait for the sample file.
0
 

Author Closing Comment

by:ssmith94015
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
This collection of functions covers all the normal rounding methods of just about any numeric value.
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 is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now