Solved

Converting Excel Formulas to a VBA macro or module

Posted on 2008-10-29
4
524 Views
Last Modified: 2013-11-25
Experts

I am just starting down the road in terms of VBA and macros/modules, I do a lot of data manipulation with very large spreadsheets.  The spreadsheets contain many complex formulas, it is obviously easier to manipulate, sort, etc an excel file without formulas, actually my files crash often when I sort with these formulas present.

So my question:  In the workbook attached the first several columns with the green header is static meaning no formulas, the rest of the spreadsheet in yellow is all populated via the use of formulas which you can see in the first few rows of data.  I would like to have a macro or module or some type of vba script that would analyze my data and populate the excel file in the yellow areas with "VALUES" only and not formulas.

Not sure how to do it but if I could get an example in VBA for a few of the columns and how to insert it in excel, run it etc I could probably figure out the rest.

Formula snipet and file attached

Thanks
=IF(J3<>"Weekend","Weekday",IF($Z3="","No NADM",IF(OR(AA3<=$L3,$O3<=Z3,AA3-Z3<0.084),"NA Does Not Apply",IF(AND((TEXT(WEEKDAY(L3),"ddd"))="Sat",Z3<=($L3+0.084),AA3>=((INT($L3)+2+'Ref Data'!$B$2))),"Yes",IF(AND((TEXT(WEEKDAY(L3),"ddd"))="Sun",Z3<=($L3+0.084),AA3>=((INT($L3)+1+'Ref Data'!$B$2))),"Yes","No")))))

Open in new window

OOH-Example-Data.xls
0
Comment
Question by:jclem1
  • 3
4 Comments
 
LVL 39

Expert Comment

by:nutsch
ID: 22834051
The easiest might be to just use Vba to copy the formula to the range, then do a paste values so you only show the result.

That's something you could do by recording a macro.

Thomas
0
 
LVL 1

Author Comment

by:jclem1
ID: 22834866
I guess in simplest terms I would like to see a VBA example of a formula in a column and then of course how to copy it down etc.
0
 
LVL 39

Accepted Solution

by:
nutsch earned 500 total points
ID: 22835429
This is an example (I limited to columns AN to AR)


Sub Macro1()
 
Dim lastRow As Long
 
lastRow = Range("A65536").End(xlUp).Row
 
    Range("AN3:AN" & lastRow).FormulaR1C1 = "=IF(RC[-21]<=4,""Yes"",""No"")"
    Range("AO3:AO" & lastRow).FormulaR1C1 = _
        "=IF(OR(RC[3]=""No"",RC[-31]=""Overnight"",RC[-31]=""Evening"",RC[-31]=""weekend""),""Yes"",""No"")"
    Range("AP3:AP" & lastRow).FormulaR1C1 = _
        "=IF(RC[1]="""",IF(AND(RC[9]=""No"",RC[10]<>""yes"",RC[11]<>""Yes"",RC[12]<>""Yes"",RC[13]<>""Yes""),""MISSED: Weekend"",IF(OR(RC[15]='Ref Data'!R22C1,RC[16]='Ref Data'!R22C1,RC[17]='Ref Data'!R22C1,RC[18]='Ref Data'!R22C1,RC[19]='Ref Data'!R22C1,RC[20]='Ref Data'!R22C1,RC[21]='Ref Data'!R22C1, RC[22]='Ref Data'!R22C1,RC[23]='Ref Data'!R22C1,RC[24]='Ref Data'!R22C1,),""Access Not Avail"",IF(RC[-2]=""Yes"",""MET Other"",""MISSED""))),RC[1])"
    Range("AQ3:AQ" & lastRow).FormulaR1C1 = _
        "=IF(RC[8]=""Yes"",""MET: HDD & DSP Weekend"",IF(RC[1]=""Yes"","" Not OOH"",IF(RC[2]=""yes"",""MET:  HDD & DSP Same OOH Period"",IF(RC[3]=""Yes"",""MET: HDD Day & DSP Same Evening"",IF(RC[4]=""Yes"",""MET:  HDD Day and DSP Next Day AM OOH"",IF(RC[6]=""Yes"",""MET: HDD > 0400 DSP 1st Job"",IF(OR(RC[9]=""yes"", RC[10]=""Yes"", RC[11]=""Yes"", RC[12]=""Yes""),""Weekend Acc Not Avail"", """")))))))"
    Range("AR3:AR" & lastRow).FormulaR1C1 = _
        "=IF(INT(RC[-32])<>(INT(RC[-30])),""No"",IF(AND(AND(MOD(RC[-32],1)>='Ref Data'!R6C2,MOD(RC[-32],1)<='Ref Data'!R9C2),AND(MOD(RC[-30],1)>='Ref Data'!R6C2,MOD(RC[-30],1)<='Ref Data'!R9C2)),""Yes"",""No""))"
    
    Range("AN3:AR" & lastRow).Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
End Sub

Open in new window

0
 
LVL 39

Expert Comment

by:nutsch
ID: 22843101
Thanks for the grade. Glad to help.

Thomas
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question