copy values

rollingzep

Board Regular
Joined
Nov 18, 2013
Messages
224
Office Version
  1. 365
Platform
  1. Windows
Hi,

In my Excel workbook, I have a column BA called Sec which contains various values.
I have another column AH, which is product description.

I use VBA for coding. Among other values of Sec, for one particular value, "BARD" it has to be replaced by the value in product description column.
The col AG is product.

VBA Code:
LastRow = ws.Range("AG" & Rows.Count).End(xlUp).Row

For i=2 To LastRow

If ws.Range("BA" & i).Value = "BARD" Then

   ws.Range("BA" & i).Value = .................................. ' (copy and paste the value of AH)

End If

Next i

How to get the values of AH into BA for that specific row. I mean it has to copy and paste the value of AH of that row to the row in BA.

TIA
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Something like this perhaps.
VBA Code:
Sub ReplaceBARDWithProductDescription()
    Dim ws As Worksheet
    Dim LastRow As Long
    Dim i As Long

    Set ws = ThisWorkbook.Sheets("Sheet1")
    LastRow = ws.Range("AG" & ws.Rows.Count).End(xlUp).Row

    For i = 2 To LastRow
        If ws.Range("BA" & i).Value = "BARD" Then
            ws.Range("BA" & i).Value = ws.Range("AH" & i).Value
        End If
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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