Solved

Converting Excel Formulas to a VBA macro or module

Posted on 2008-10-29
4
532 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 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

695 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