Paste Values

ch46guy

New Member
Joined
Apr 29, 2013
Messages
29
I'm really new to VBA. I'm trying to cycle through a worksheet and if the cell has a "0" then I want it to paste "UNK". Any help would be appreciated.

Thanks,
Code:
Public Sub change()
Dim totalRow As Long
'totalRow = Sheet1.Range(Rows.count).End(xlUp).Row
totalRow = 10000
Dim startRow As Integer
startRow = 4
Dim i As Integer
Dim UNK As String
UNK = "UNK"
i = 4


Do Until i = totalRow
    If (Sheet1.Cells(startRow, 5)) = "0" Then Sheet1.Cells(startRow, 5).Paste (UNK)
     If (Sheet1.Cells(startRow, 6)) = "0" Then Sheet1.Cells(startRow, 6).Paste (UNK)
      If (Sheet1.Cells(startRow, 7)) = "0" Then Sheet1.Cells(startRow, 7).Paste (UNK)
       If (Sheet1.Cells(startRow, 8)) = "0" Then Sheet1.Cells(startRow, 8).Paste (UNK)
    startRow = startRow + 1
    i = i + 1
    Loop
    
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Figured it out.

Code:
If (Sheet1.Cells(startRow, 5)) = "0" Then Sheet1.Cells(startRow, 5).Value = "UNK"
 
Upvote 0
Smitty.

Thanks for the welcome. I didnt use the Find and Replace because some of the other columns had "0" and I didnt want those changed.
 
Upvote 0
Then you just select the columns that you need changed and F&R will ignore the rest.
 
Upvote 0

Forum statistics

Threads
1,216,487
Messages
6,130,949
Members
449,608
Latest member
jacobmudombe

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