Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-08
4
Medium Priority
?
225 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

782 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