Would a function within the sub be suitable?

smakatura

Board Regular
Joined
May 27, 2011
Messages
141
I have two excel sheets. 06-03-11 tmp.csv and call log master.xlsx. I have opened call log master.xlsx - so it is my active workbook.

I have the following code starting my macro. Will call it "startercode" for reference in this posting

startercode:
HTML:
'***Set variables/Input boxes***   
    Dim tmpdate As String
    Dim rpttype As String
 
    tmpdate = InputBox("What is the TMP Date?")
    rpttype = InputBox("What is the Report Type")
    tmpfilename = tmpdate & " tmp.csv"
    filename = rpttype & "call log master.xlsx"
 
 '***clear current numbers*********
    Range("V1:Y1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
 
 '***open csv file*********
    ChDir _
        "C:\Users\smakatura\Documents\call report\"
    Workbooks.Open filename:= _
        "C:\Users\smakatura\Documents\call report\prep documents\" &
         tmpfilename

if rpttype is "" (blank), I want to perform the following code (will call it "copycode" for refernce in this posting

copycode:
HTML:
 '***copy and paste from tmp.csv to call log master.xlsx*********
    Range("A2:D2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Windows(filename).Activate
    Range(v1).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        Range("A1").Select
    Application.CutCopyMode = False
    ActiveWorkbook.Save

Column E contains values of career services, admissions, and blank cells. if rpttype = "career services",

I want to do
startercode
careercode (listed below)
copycode

careercode:
HTML:
 '***select only Career Service entries*********
    Range("F1").Select
    ActiveCell.FormulaR1C1 = "CS?"
    Selection.AutoFilter
    Range("F2").Select
    ActiveCell.FormulaR1C1 = "=IF(RC[-1]=""career services"",""x"","""")"
    Range("F2").Select
    Selection.AutoFill Destination:=Range("F2:F1499")
    Range("F2:F1499").Select
    Range("A1").Select
 
    ActiveWorkbook.Worksheets("06-03-11 tmp").AutoFilter.Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("06-03-11 tmp").AutoFilter.Sort.SortFields.Add Key _
        :=Range("F2"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.Worksheets("06-03-11 tmp").AutoFilter.Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
 
    ActiveSheet.Range("$A$1:$F$1499").AutoFilter Field:=6, Criteria1:="<>"

the real world reason for the coding difference is that if it is a career services report it only shows the names that have career services in column e. other than that it shows all the names.

Also the date on the tmp.csv file can change so that is why I am using the inputbox for that part.

I am not sure of the best way to do this. I understand that if-then statements work but I was not sure how they worke with multiple commands within the actions portions.
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,214,593
Messages
6,120,434
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top