?
Solved

Converting Excel Formulas to a VBA macro or module

Posted on 2008-10-29
4
Medium Priority
?
537 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

765 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