VBA - Find X / Paste Special as Value

Sundae

New Member
Joined
Jul 25, 2011
Messages
44
Hi All,

I am new to VBA and need some assistance. I need to store this in VBE as it will become part of my application:

I need to find a specific value in Column A, ie: "Number", if Number is found in Column A in cell A5, then the formula in cell B5 needs to be pasted as a value. I would want the code to repeat this process for each string of "Number" in column A.

I hope I have explained this thoughtfully.

Thanks,
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I need to find a specific value in Column A, ie: "Number", if Number is found in Column A in cell A5, then the formula in cell B5 needs to be pasted as a value. I would want the code to repeat this process for each string of "Number" in column A.
Some questions...

1) The word "Number" that is found in Column A... where exactly did you want its corresponding Column B value pasted to? On top of itself? One column over and on the same row that "Number" is found? In a contiguous list in some unused column?

2) Is the word "Number" the only text that will be in the cell, or could it be embedded among other text?

3) What is in Column A... constant values or formulas?
 
Upvote 0
Thanks for the quick reply....

Some questions...

1) The word "Number" that is found in Column A... where exactly did you want its corresponding Column B value pasted to? On top of itself? One column over and on the same row that "Number" is found? In a contiguous list in some unused column?

A: On top of itself.

2) Is the word "Number" the only text that will be in the cell, or could it be embedded among other text?

A: Only text in cell, matchcase = true

3) What is in Column A... constant values or formulas?

A: constant values
 
Upvote 0
Try this:

Code:
Sub test()
Dim x As Long
Dim lastrow As Long
lastrow = ActiveSheet.UsedRange.Rows.Count
For x = 1 To lastrow
    If Range("A" & x).Value = "Number" Then
        Range("B" & x).Copy
        Range("B" & x).Select
        Selection.PasteSpecial Paste:=xlPasteValues
    End If
Next x
End Sub
 
Upvote 0
Thank you so much - this works perfectly!!!
Based on the postings so far, can we conclude that Column B contains formulas and that some of those formulas are displaying numerical values while the rest are either displaying the empty string ("") or some other non-numerical text? Also, can we conclude that for every number being displayed in Column B, that Column A is displaying the word "Number"? If so, then you can convert those formula-numbers to real numbers using two lines of code...

Code:
On Error Resume Next
Columns("B").SpecialCells(xlFormulas, xlNumbers).Value = Columns("B").SpecialCells(xlFormulas, xlNumbers).Value
 
Upvote 0
Thanks. I am going to stick with the initial code you provided, as the most recent assumptions you made are not accurate.

Thank you again!
 
Upvote 0
Thanks. I am going to stick with the initial code you provided, as the most recent assumptions you made are not accurate.!
Actually, I had not posted any code previously; instead, I asked you some questions and then completely missed that you had answered those question. Based on your answers, this code should do what you want and I think it will do it faster than Jose's code (no looping is involved with my code)...

Code:
Sub ProcessNumberCells()
  Columns("A").Replace "Number", "=Number", xlWhole
  On Error Resume Next
  With Columns("A").SpecialCells(xlFormulas)
    .Offset(, 1).Value = .Offset(, 1).Value
    .Replace "=", "", xlPart
  End With
End Sub
 
Upvote 0
My apologizes - I did not realize that Jose had also responded - I will be more careful in the future.

Thank you for the vba code - you are awesome!
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

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