Forum Discussion
sf49ers19238597
Aug 14, 2021Iron Contributor
I need help with convert formulas to vba codes
I not sure how to convert formulas to VBA Codes. Thanks You Thomas
- Aug 14, 2021
Please give this a try...
Sub InsertFormulas() Dim wsPTW4 As Worksheet Dim lr As Long Application.ScreenUpdating = False Set wsPTW4 = ThisWorkbook.Worksheets("PICK THEM WEEK 4") lr = wsPTW4.Cells(Rows.Count, 1).End(xlUp).Row 'Formula for Column C With wsPTW4.Range("C3:C" & lr) .Formula = "=IF('4'!D2<>"""",'4'!D2,""BYE WEEK TEAM"")" .Value = .Value End With 'Formula for Column D With wsPTW4.Range("D3:D" & lr) .Formula = "=VLOOKUP(C3,INPUT_SCORES!$A$2:$R$33,5,0)" .Value = .Value End With 'Formula for Column G With wsPTW4.Range("G3:G" & lr) .Formula = "=IF('4'!G2<>"""",'4'!G2,""BYE WEEK TEAM"")" .Value = .Value End With 'Formula for Column H With wsPTW4.Range("H3:H" & lr) .Formula = "=VLOOKUP(G3,INPUT_SCORES!$A$2:$R$33,5,0)" .Value = .Value End With 'Formula for Column L With wsPTW4.Range("L12:L17") .Formula = "=IF('BYE WEEKS'!K2<>"""",'BYE WEEKS'!K2,"""")" .Value = .Value End With Application.ScreenUpdating = True End Sub
DKoontz
Sep 15, 2021Iron Contributor
Is the .Value = .Value used within a With block used to value it out?
Subodh_Tiwari_sktneer
Sep 16, 2021Silver Contributor
Yes, it converts formulas to their corresponding values.
- DKoontzSep 16, 2021Iron ContributorAwesome! I was pasting as value lol, this is much cleaner.
- Subodh_Tiwari_sktneerSep 16, 2021Silver Contributor
Thanks DKoontz!
- sf49ers19238597Sep 16, 2021Iron Contributorsome of code is red on my end
- Subodh_Tiwari_sktneerSep 16, 2021Silver Contributor
That may be due to the editor's settings perhaps. If the code works as expected, nothing to worry about then.