Replace adjacent cells with value within IF statement

apo

Well-known Member
Joined
Nov 3, 2008
Messages
581
HI..

I have made the following macro to clean up some data...

It successfully replaces "GR" with "KG" in the required place...

The thing i need help with is that I need (within that IF statement) .. it to also replace the adjacent cells (i,10) and (i,11) with "1" and "KG" respectively..

I'm stuck on this.. any help will be appreciated.. thanks

Code:
Private Sub CommandButton1_Click()


Dim LR As Long, i As Long


Application.ScreenUpdating = False
LR = Range("I" & Rows.Count).End(xlUp).Row


For i = 1 To LR
If Right(Cells(i, 9).Value, 2) = "GR" And Cells(i + 1, 11).Value = "GR" Then
 


    With Range("I" & i)
        If Right(.Value, 2) = "GR" Then .Value = Left(.Value, Len(.Value) - 2) & "KG"
        
    End With
    
Application.ScreenUpdating = True


End If
    
Next i
   
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

patel45

Well-known Member
Joined
Jul 15, 2012
Messages
1,953
Code:
Private Sub CommandButton1_Click()
Dim LR As Long, i As Long
Application.ScreenUpdating = False
LR = Range("I" & Rows.Count).End(xlUp).Row
For i = 1 To LR
   s=Cells(i, 9).Value
   If Right(s, 2) = "GR" And Cells(i + 1, 11).Value = "GR" Then  
       Cells(i, 9).Value = Left(s, Len(s) - 2) & "KG"
       Cells(i, 10).Value = "1"
       Cells(i, 11).Value = "KG"
   end if
Next i
Application.ScreenUpdating = True  
End Sub
 
Upvote 0

Forum statistics

Threads
1,195,650
Messages
6,010,925
Members
441,573
Latest member
Goronvir

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
Top