Solved

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

Posted on 2011-03-08
4
219 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
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

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.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

803 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