VBA find formula & copy output to adjacent cell

jerrykel

New Member
Joined
Mar 31, 2011
Messages
16
Hello,
I am in need of a bit of VBA code that will copy formula output to adjacent cell. I think this is a two part problem. First, find the cells with a formula in them and then copy output to the cell on the right.

Criteria:
1. Set number of rows and columns. normally G23:BZ26.
2. Only data in range is this formula that adds other cells and gives a sum.
3. Most cells are blank and the formula cells always have a blank cell to the right. Formula cells comprise all four rows of a column.
4. I need to copy the output not the formula to the adjacent cell to the right.
5. The columns with formulas get deleted prior to publication of the spreadsheet. Put I need to output to remain
6. The columns with formulas are not at a set interval.

Thanks for any help you can give.
Jerry
 

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.
Give this a try

Code:
Sub test()
With ActiveSheet.Range("G23:BZ26").SpecialCells(xlCellTypeFormulas)
    .Offset(, 1).Value = .Value
    .Value = .Value
End With
End Sub
 
Upvote 0
Thanks for the reply VoG.
The script finds the output to the first formula cell then copies it to every cell that had a formula and the adjacent cell. This is a good start because I can now find a formula and copy to the next cell. This script also replaces the formula with the output.

Removing the final .value = .value statement means that all the formula cells stay as they are supposed to. However, only the first formula cell is copied to all the adjacent cells of formulas in the spreadsheet.

So still looking for a solution.
 
Upvote 0
Very lightly tested:
Code:
Option Explicit

Sub test()
    Dim aCell As Range
    For Each aCell In ActiveSheet.Range("a1:e10").SpecialCells(xlCellTypeFormulas)
        aCell.Offset(, 1).Value = aCell.Value
        Next aCell
    End Sub
Thanks for the reply VoG.
The script finds the output to the first formula cell then copies it to every cell that had a formula and the adjacent cell. This is a good start because I can now find a formula and copy to the next cell. This script also replaces the formula with the output.

Removing the final .value = .value statement means that all the formula cells stay as they are supposed to. However, only the first formula cell is copied to all the adjacent cells of formulas in the spreadsheet.

So still looking for a solution.
 
Upvote 0
Thanks Tushar.
This worked. My only concern is that it locks up to spreadsheet for a couple of minutes while the code runs.
 
Upvote 0
You could try, though I don't know how much it will help to adjust screenupdating and calculation as in the untested:
Code:
Option Explicit

Sub test()
    With Application
    Dim OldCalc As Long: OldCalc = .Calculation
    .Calculation = xlCalculationManual
    .ScreenUpdating = False
    Dim aCell As Range
    For Each aCell In ActiveSheet.Range("a1:e10").SpecialCells(xlCellTypeFormulas)
        aCell.Offset(, 1).Value = aCell.Value
        Next aCell
    .ScreenUpdating = True
    .Calculation = OldCalc
        End With
    End Sub


Thanks Tushar.
This worked. My only concern is that it locks up to spreadsheet for a couple of minutes while the code runs.
 
Upvote 0
Fixed the delay in the code. Turns out I had another script set to private sub worksheet_change running in the background on this worksheet. I changed it to a manual script and now both scripts run as they should.

Thanks for the help.

Jerry
 
Upvote 0

Forum statistics

Threads
1,224,534
Messages
6,179,390
Members
452,909
Latest member
VickiS

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