SOLVED

I need help with convert formulas to vba codes

%3CLINGO-SUB%20id%3D%22lingo-sub-2647443%22%20slang%3D%22en-US%22%3EI%20need%20help%20with%20convert%20formulas%20to%20vba%20codes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2647443%22%20slang%3D%22en-US%22%3E%3CP%3EI%20not%20sure%20how%26nbsp%3B%20to%20convert%20formulas%20to%20VBA%20Codes.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20You%26nbsp%3B%3C%2FP%3E%3CP%3EThomas%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2647443%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2648410%22%20slang%3D%22en-US%22%3ERe%3A%20I%20need%20help%20with%20convert%20formulas%20to%20vba%20codes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2648410%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20code%20works.%20but%20look%20bye%20in%20column%20D%20%26amp%3B%20H.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20added%20other%20worksheet%26nbsp%3B%20that%20I%20want%20look%26nbsp%3B%20when%26nbsp%3B%20look%26nbsp%3B%20Column%20L%20see%20is%20any%20team%20in.%26nbsp%3B%20column%20Colums%20C%2CD%20%26amp%3B%20G%2CH%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eweek%204%20might%20be%20more%20in%20years%20become%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2650035%22%20slang%3D%22en-US%22%3ERe%3A%20I%20need%20help%20with%20convert%20formulas%20to%20vba%20codes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2650035%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eyes%20remove%20from%20C11%3AD11%20%26amp%3B%20G11%3AH11.%20Put%26nbsp%3BBYE%20WEEK%20TEAMS%20in%20last%20cell%20or%20cells%20after%20such%20like%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20worksheet%20call%20should%20want%20look%20like.%20it%20can%20be%206%20teams%20in%20column%20L%20in%20future%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3EThanks%20You%3CBR%20%2F%3EThomas%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2754583%22%20slang%3D%22en-US%22%3ERe%3A%20I%20need%20help%20with%20convert%20formulas%20to%20vba%20codes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2754583%22%20slang%3D%22en-US%22%3Ecan%20put%20notes%20in%20code%20the%20do%20I%20can%20not%20configure%20out%20what%20codes%20id%20doing%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2754585%22%20slang%3D%22en-US%22%3ERe%3A%20I%20need%20help%20with%20convert%20formulas%20to%20vba%20codes%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2754585%22%20slang%3D%22en-US%22%3EIs%20the%20.Value%20%3D%20.Value%20used%20within%20a%20With%20block%20used%20to%20value%20it%20out%3F%3C%2FLINGO-BODY%3E
Contributor

I not sure how  to convert formulas to VBA Codes.  

 

Thanks You 

Thomas

11 Replies
best response confirmed by sf49ers (Contributor)
Solution

@sf49ers 

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

@Subodh_Tiwari_sktneer 

 

The code works. but look bye in column D & H.

 

 

I added other worksheet  that I want look  when  look  Column L see is any team in.  column Colums C,D & G,H

 

week 4 might be more in years become

 

Your question was, how to place formulas with VBA and I provided the solution for that.

So now, do you want to remove a team from column C if the corresponding cell in column D says 'Bye' and remove a team from column G if the corresponding cell in column H says 'Bye' in the end?

Also, do you want to place the text 'BYE WEEK TEAMS' in the end? e.g. what you showed in cells C17 and G17 on 'HERE SHOULD WANT LOOK LIKE' Sheet?

 

 

yes remove from C11:D11 & G11:H11. Put BYE WEEK TEAMS in last cell or cells after such like 

The worksheet call should want look like. it can be 6 teams in column L in future



Thanks You
Thomas

can put notes in code the do I can not configure out what codes id doing
Is the .Value = .Value used within a With block used to value it out?

@DKoontz 

Yes, it converts formulas to their corresponding values.

some of code is red on my end
Awesome! I was pasting as value lol, this is much cleaner.

@sf49ers 

That may be due to the editor's settings perhaps. If the code works as expected, nothing to worry about then.