Formula to Text based on condition "if cell = 1"

morenac

New Member
Joined
Jun 23, 2017
Messages
12
Hello all,

I struggle with one thing, I would need to divide all figures in particular range of row by 1000 and then the formulas paste as text, if first cell will contain "1".

It means, table starts in row 21, range G21:G999 will contain "1" or "0", and range H21:AS999 contains formulas.
I would need to divide all the cells by 1000 and then paste all cells in row H21:AS21 as text IF cell G21 contain "1".
If G21 will be "0", it will do nothing and go to next line and repeat.

Could please someone help with writing this code? Unfortunately this is too much for me, I would be really really grateful!

Thank you all!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
What do these formulas in cells H21:AS999 look like?
Do they all return numbers?
Are any dependent on other formulas within that same range?
When you say "paste formulas as text", do you really mean post the hard-coded value instead of the formula?
 
Last edited:
Upvote 0
Hello Joe4,

I am sorry, if I wrote it unclear. Actually H21:AS999 are mostly only links to other sheets, all of them are numbers - these would be marked with "1" in column G. For all these lines I would need just to replace formulas with its hard-coded value.

But some of the rows of H21:AS999 contains SUM formula for few cells above - these would be marked with "0" in column G and these lines should keep the SUM formula.
I thought that the 1 and 0 in G column would be best way how to recognize which line should be hard-coded and which should not be touched, because the line quantity will change, so I can not specify exact range of the replacing fomula by hard number.

So in practice there is for example
H21:H23 link to another sheet,
H24 is SUM(H21:H24),
then H25:H30 with link to another sheet
H31 is SUM(H25:H30) and so on for each column untill AS999

Thank you very much for your effort!
 
Upvote 0
Try this:
Code:
Sub MyCopyMacro()

    Dim myRow As Long
    Dim myCol As Long
    Dim myRange As Range
    
    Application.ScreenUpdating = False
    
'   Store 1000 in some unused cell
    Range("AZ1") = 1000
    
'   Loop through rows 21-999
    For myRow = 21 To 999
'       Check to see if column G equals 1
        If Cells(myRow, "G") = 1 Then
'           Set range to apply to
            Set myRange = Range("H" & myRow & ":AS" & myRow)
'           Hardcode range to value
            myRange.Value = myRange.Value
'           Divide range by 1000
            Range("AZ1").Copy
            myRange.PasteSpecial Paste:=xlPasteAll, Operation:=xlDivide, SkipBlanks _
                :=False, Transpose:=False
        End If
    Next myRow
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,434
Members
448,961
Latest member
nzskater

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