if a is and c is then b = x

AndrewNH

New Member
Joined
Jan 19, 2019
Messages
4
hi I was wondering if someone could help I am trying to write a macro to change data in a cell if spacific data is in two other cells I will have various different variations of the data but the basic struture evades me.
i hav something along these lines, there is a large sheet of data that had to be run everyday and the information changes daily
could someone help with this macro ?
If Range("A").Value = "BNSSG Extra Demand" And Range("E").Value = "Almondsbury " Then Replace.Value("B") = "Almondsbury"
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
This will be slow and there could be quicker ways but you havent given us enough info to know if other methods are possible. You need to change sheet name to suit.

Code:
With Sheets("Sheet1")
    lr = .Cells(.Rows.Count, "A").End(xlUp).Row
    For i = 1 To lr
        If .Range("A" & i).Value = "BNSSG Extra Demand" Then
            If .Range("E" & i).Value = "Almondsbury" Then
                .Range("B" & i).Value = "Almondsbury"
            End If
        End If
    Next
End With
 
Upvote 0
thanks With a few mods I got this to work for me, although I do have a lot more values to change the value of E and B need to change to search for other changes could this be added in after the Range "B" line or do i need to add this after the Next statement?
 
Upvote 0
Hi Steve, they are all based in the same columns just varying data based on locations probably six locations. Thanks this will make the daily report much smoother
 
Upvote 0
Yes but you will need to feed the code with what they are. Do you have them in a separate list somewhere or do you want to hardcode them into the code? It will change the way it is written.
 
Upvote 0
Here you are. Put your values you want to search for in the array:

Code:
arr = Array("Almondsbury", "Wherever")

With Sheets("Sheet1")
    lr = .Cells(.Rows.Count, "A").End(xlUp).Row
    For i = 1 To lr
        If .Range("A" & i).Value = "BNSSG Extra Demand" Then
            For a = LBound(arr) To UBound(arr)
                If LCase(.Range("E" & i).Value) = LCase(arr(a)) Then
                    .Range("B" & i).Value = arr(a)
                End If
            Next
        End If
    Next
End With
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,317
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top