Replace values on multiple worksheets

excel_2009

Active Member
Joined
Sep 14, 2009
Messages
308
Hi All,

I have the following information on my "Home" worksheet:

Column AColumn B
Sku8008989
TitleBrand new in box
Quantity
BrandSergio Technini

<tbody>
</tbody>

I also have several worksheets called: Data 1, DataSheet 2, Misc which contains near identical information, the aim is to replace the current values in these worksheets with the values above (in column B, Home worksheet) IF the values are populated, if they're blank then nothing will be replaced i.e in the example above the Quantity value would be ignored and the original Quantity value would remain as is on the Data 1, DataSheet2 and Misc worksheet.

The worksheet information is structured in the following manner (in one Column, always Column A - irrespective of worksheet):

"Sku": "5170092602",

<tbody>
</tbody>
"Title": "Test do not buy",

<tbody>
</tbody>
"Quantity": 1,

<tbody>
</tbody>
"Brand": "Nike",

<tbody>
</tbody>

<tbody>
</tbody>

So with the above in mind the following would be updated to show the following (based on the input provided on the Home worksheet):

"Sku": "8008989",

<tbody>
</tbody>
"Title": "Brand new in box",

<tbody>
</tbody>
"Quantity": 1,

<tbody>
</tbody>
"Brand": "Sergio Technini",

<tbody>
</tbody>

<tbody>
</tbody>


Does anyone know how this can be achieved?

Many thanks!!!
 

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
8,529
Try:
Code:
Sub ReplaceVal()
    Application.ScreenUpdating = False
    Dim LastRow As Long, rng As Range, splitRng As Range, ws As Worksheet, srcWS As Worksheet, fnd As Range
    Set srcWS = Sheets("Home")
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For Each rng In srcWS.Range("A1:A" & LastRow)
        If rng.Offset(0, 1) <> "" Then
            For Each ws In Sheets
                If ws.Name <> "Home" Then
                    Set fnd = ws.Range("A:A").Find("""" & rng & """", LookIn:=xlValues, lookat:=xlPart)
                    If Not fnd Is Nothing Then
                        fnd = Replace(fnd, Split(fnd, ": ")(1), """" & rng.Offset(0, 1) & """,")
                    End If
                End If
            Next ws
        End If
    Next rng
    Application.ScreenUpdating = True
End Sub
 

excel_2009

Active Member
Joined
Sep 14, 2009
Messages
308
Wow, this is fantastic!!!, thank you so much!! works perfectly :) have a great day!!!!!
 

excel_2009

Active Member
Joined
Sep 14, 2009
Messages
308
Actually there is one last thing!, I did try and merge some exisisting working coding alongside yours but the values aren't updating, any idea why this might be? (the previous code is stored in the sheet and not as a macro, the idea is for the dropdown to be selected and the values are updated (if any) thereafter the selected worksheet is copied to the clipboard :)

Code:
Private Sub Worksheet_Change(ByVal Target As Range)



    
    Dim LastRow As Long, rng As Range, splitRng As Range, ws As Worksheet, srcWS As Worksheet, fnd As Range
    Set srcWS = Sheets("Home")
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For Each rng In srcWS.Range("D4:D9" & LastRow)
        If rng.Offset(0, 1) <> "" Then
            For Each ws In Sheets
                If ws.Name <> "Home" Then
                    Set fnd = ws.Range("A:A").Find("""" & rng & """", LookIn:=xlValues, lookat:=xlPart)
                    If Not fnd Is Nothing Then
                        fnd = Replace(fnd, Split(fnd, ": ")(1), """" & rng.Offset(0, 1) & """,")
                    End If
                End If
            Next ws
        End If
    Next rng










If Target.Address = Range("D10").Address Then
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
On Error GoTo M
Dim LastRow2 As Long
Dim ans As String
ans = Target.Value
LastRow2 = Sheets(ans).Cells(Rows.Count, "A").End(xlUp).Row
Sheets(ans).Range("A1:A" & LastRow2).Copy
End If




Exit Sub
M:
MsgBox "There is no sheet named  " & ans


    Application.ScreenUpdating = True


End Sub
 

Forum statistics

Threads
1,082,314
Messages
5,364,475
Members
400,802
Latest member
RichBRich

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top