Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all 89171 articles
Browse latest View live

Bold Top 50% of the summed values in Column E and their rows

$
0
0

After seeking help in stackoverflow, I came back with the skeleton of the vba codes (still not working though), however it is not generating the outcome that I desire.

Sub Highlight_Top50()

    Dim CheckRange As range

    Set CheckRange = range("E2:E", Cells(Rows.Count, "E").End(xlUp)).Row

    Selection.FormatConditions.AddTop10
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1)
    .TopBottom = xlTop10Top
    .Rank = 50
    .Percent = True
    End With

    With Selection.FormatConditions(1).Font.Bold = True

    End With

    Selection.FormatConditions(1).StopIfTrue = False

End Sub

Under Conditional Formatting, there's no such rule as "Highlight Top 50% of the summed value". The nearest Excel provides is "Format cells that rank in Top: x%".


c# application excel vsto conditional formatting

$
0
0

I have a VSTO c# application and I am trying to apply conditional formatting so when the value in Column V is set to No make the whole row grey. headercount variable is my last column number

      Microsoft.Office.Interop.Excel.FormatCondition format7 = (Microsoft.Office.Interop.Excel.FormatCondition)(uiWorksheet.get_Range("B7:Z" + headercount,
  Type.Missing).FormatConditions.Add(Microsoft.Office.Interop.Excel.XlFormatConditionType.xlExpression, Microsoft.Office.Interop.Excel.XlFormatConditionOperator.xlEqual,
  "V=No", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing));
        format7.Interior.Color = true;

I tried the below but it doesnt work - any ideas?

DAX calculate an average of a column when taking cells that contain only numbers

$
0
0

There are two types of values in a column: integers and NULL (string).
Trying to figure out how to create a DAX formula to calculate an average for the column that would take only cells that contain integers.
It feels that the next basic formula would work:

=CALCULATE ( 
        AVERAGE ( tData[columnA]),
        FILTER (    tData, [columnA] <> "NULL" )
               )

but it throws an error: The function AVERAGE takes an argument that evaluates to numbers or dates and cannot work with values of type String.

I'm wondering if there is a way to avoid this error without removing/cleaning NULLs values beforehand?

How to set date range in VBA coding to extract SAP reports

$
0
0

I'm a newbie to excel VBA coding. I used script recording but I'm not sure how to setup date range from current date to 2 months intervals to extract report from SAP.

Following are my codes: enter image description here

Dim SapGuiAuto As Variant
Dim SAPApp As Variant
Dim SAPCon As Variant
Dim session As Variant


Set objSheet = ActiveWorkbook.ActiveSheet
Set SapGuiAuto = GetObject("SAPGUI")  
Set SAPApp = SapGuiAuto.GetScriptingEngine  
Set SAPCon = SAPApp.Children(0) 
Set session = SAPCon.Children(0) 

session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "/nzpp_shop_ready"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[17]").press
session.findById("wnd[1]/usr/txtENAME-LOW").text = ""
session.findById("wnd[1]/usr/txtENAME-LOW").setFocus
session.findById("wnd[1]/usr/txtENAME-LOW").caretPosition = 0
session.findById("wnd[1]").sendVKey 0
session.findById("wnd[1]/tbar[0]/btn[8]").press

session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").currentCellRow = 5
session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").selectedRows ="5"

session.findById("wnd[1]/usr/cntlALV_CONTAINER_1/shellcont/shell").doubleClickCurrentCell

session.findById("wnd[0]/usr/ctxtS_DATE-HIGH").setFocus
session.findById("wnd[0]/usr/ctxtS_DATE-HIGH").caretPosition = 5
session.findById("wnd[0]").sendVKey 4
session.findById("wnd[1]/usr/cntlCONTAINER/shellcont/shell").focusDate = "20191207"
session.findById("wnd[1]/usr/cntlCONTAINER/shellcont/shell").selectionInterval = "20191207,20191207"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[45]").press
session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[4,0]").select
session.findById("wnd[1]/usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[4,0]").setFocus
session.findById("wnd[1]/tbar[0]/btn[0]").press

Typing in password for every connected table from SQL Server Excel 2010 Powerpivot Addin

$
0
0

I've got a BI Dashboard in Excel 2010 using Powerpivot, which is connected to a number queried tables on one SQL Server. When the connections were setup, I checked the box to 'save password' on each one. However, whenever my users reopen the document and go to the Powerpivot window and select 'RefreshAll' then they have to type in the password multiple times (once for each table), which is not suitable.

I have looked here and here and seem to be experiencing the same issue as a number of other people. I have started again from scratch, ensuring that the 'save password' box is definitely checked on each connection string.

The only workaround I can think of is by user Windows Authentication, but this document is intended for widespread use, and as such this will require a lot of maintenance, and will really annoy my server admin :)

Does anyone have a workaround, or any way of resolving the problem?

IsError (GetObject(, "word.application")) is returning an error when word is not running instead of returning true

$
0
0

So I am working on opening a series of files from excel, manipulating them, and saving them as PDF. I was thinking that it would be better to start MSWord before going into the loop that opens each files then closes the file instead of starting and closing word for each file. That got me thinking that I also should not start word if it is already running.

I was trying to avoid using on error resume next so I tried the following code:

If IsError(GetObject(, "word.application")) Then
    Set MSWordApp = CreateObject("word.application")
    MSWordVisState = False
    AlreadyRunning = False
Else
    Set MSWordApp = GetObject(, "word.application")
    MSWordVisState = MSWordApp.Visible
    AlreadyRunning = True
End If

Which works great... AS LONG AS WORD IS ALREADY RUNNING!!!!

If word is not already running ISERROR returns and error instead of returning true. What am I missing/not understanding?

Is there a method for testing without using on error resume next? I swear I have stumble on this concept in the past but am having difficulties find it now.

UPDATE

The error code for those that may be wondering is "Run-time error '429': ActiveX component can't create object"

What I am currently using

    On Error GoTo StartWord
        Set MSWordApp = GetObject(, "word.application")
        MSWordVisState = MSWordApp.Visible
        AlreadyRunning = True
        GoTo WordGood

StartWord:
    Set MSWordApp = CreateObject("word.application")
    MSWordVisState = False
    AlreadyRunning = False
    On Error GoTo 0

WordGood:
    MSWordApp.Visible = False
    'Carry on with rest of MAIN sub

MSWordApp.Visible = MSWordVisState
If Not AlreadyRunning Then MSWordApp.Quit

How to subtract Excel cells using Powershell

$
0
0

I am trying to perform arithmetic on an existing excel sheet that has figures in it. My code:

$Excel = New-Object -ComObject Excel.Application
$ExcelWorkBook = $Excel.Workbooks.Open($temp)
$ExcelWorkSheet = $Excel.WorkSheets.item(1)
$ExcelWorkSheet.activate()



$Prehit = $ExcelWorkSheet.Cells.Item(2,1)
$Hit1 = $ExcelWorkSheet.Cells.Item(2,2)
$Hit2 = $ExcelWorkSheet.Cells.Item(2,3)
$Hit3 = $ExcelWorkSheet.Cells.Item(2,4)

$Remain = 0


If ($hit -eq 1) {
  $Remain = $Prehit - $Hit1

  }



If ($hit -eq 2) {
  $Remain = $Prehit - $Hit1- $Hit2

  }

Yields the following error:

Method invocation failed because [System.__ComObject] does not contain a method named 'op_Subtraction'.
At C:\path_to_ps1_file.ps1:40 char:3
+   $Remain = $Prehit - $Hit1- $Hit2
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (op_Subtraction:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

I have tried casting all the variables as ints yet that yields the same error. I even casted the numbers as ints in the powershell modules used to create this excel file. What am I missing?

Consider a row unique based on column 5 then column 4

$
0
0

With two open files I can compare if an entry (ID Number from the 1st file) is in column 5 on both lists. If yes, copy same row, column 4 to the second file. Otherwise put the complete row in the first empty row in the second file. That is working fine.

I noted some IDs are twice in list 1, but with different Information in column 4. If it is different information in column 4, the script should not overwrite in file 2, even if the ID (column 5) is double. It should insert it like the ID does not exist in column 5.

my_FileName = Application.GetOpenFilename(FileFilter:="Excel Files,*.xlsx")

On Error Resume Next
   Set wkb = Workbooks.Open(Filename:=my_FileName)
   Set wkb1 = ThisWorkbook
   wkb1.Activate
   Set wks = wkb.Worksheets(1)
   Set wks1 = wkb1.Worksheets(1)
   anz = wks.Cells(65536, 5).End(xlUp).Row
   anz1 = wks1.Cells(65536, 5).End(xlUp).Row
   Cpt = anz

   For Z = 2 To anz1
       suchwert = wks1.Cells(Z, 5)
       With wks.Range("E2:E"& anz)
           Set c = .Find(suchwert, LookIn:=xlValues, LookAt:=xlWhole)
           If Not c Is Nothing Then
               For s = 4 To 5
                   wks.Cells(c.Row, s) = wks1.Cells(Z, s)
               Next
           Else
               Cpt = Cpt + 1
               wks.Cells(Cpt, 1) = wks1.Cells(Z, 1)
               wks.Cells(Cpt, 2) = wks1.Cells(Z, 2)
               wks.Cells(Cpt, 3) = wks1.Cells(Z, 3)
               wks.Cells(Cpt, 4) = wks1.Cells(Z, 4)
               wks.Cells(Cpt, 5) = wks1.Cells(Z, 5)
               wks.Cells(Cpt, 6) = wks1.Cells(Z, 6)
               wks.Cells(Cpt, 7) = wks1.Cells(Z, 7)
               wks.Cells(Cpt, 8) = wks1.Cells(Z, 8)
               wks.Cells(Cpt, 9) = wks1.Cells(Z, 9)
               wks.Cells(Cpt, 3).NumberFormat = "d.m.yyyy"
               wks.Cells(Cpt, 6).NumberFormat = "#,##0.00"
               wks.Cells(Cpt, 8).NumberFormat = "#,##0.00"   
           End If
       End With
   Next Z

Deleting all but the max of a row is inconsistent

$
0
0

I have been working on a code that deletes cells that do not contain the max of that given row.

This code would be used in files with a similar layout, just different data.

It worked the first time. However, when I try it in other files with the same conditions and different data, the code sometimes deletes entire rows, even if there is an evident max. The deleted rows are random across files.

I tried a less complicated condition by setting the rule to bold the max instead of deleting. However, the problem repeats (it does not highlight the max of some rows. The same ones that were not deleted before). This leads me to believe that the problem is with either the max itself or something in the cells.

Sub deletenonmax()
Dim rng As Range, cell As Range
Dim max As Integer

Set rng = Range("$E$10:"& Range("E10").End(xlToRight).Address) '<-- first of my rows
Do While rng(1) <> ""'<-- If excel does not detect a blank cell on the first position
    max = Application.WorksheetFunction.max(rng) '<-- This is how I get the max of current row
    For Each cell In rng '<-- loop through the cells of the row
        If cell.Value <> max Then '<-- if the value of the cell is not the max
            cell.Value = ""'<-- set it to empty
        End If
    Next cell
    Set rng = Range(rng(1).Offset(1, 0).Address & ":"& rng(1).Offset(1, 0).End(xlToRight).Address) '<-- Go to the line below
    rng.Select
Loop
End Sub

In some cases it deletes everything BUT the max values of the row.

In some cases the entire row ends up empty.

Excel to PowerPoint

$
0
0

I am trying to prepare a presentation from Excel. As of now VBA code is preparing "n number of "presentations as per no of times Loop runs. I want Code to generate just 1 presentation with all slides combined. Fist Macro "Addnumber" is run, which run Macro "ExcelRangeToPowerPoint". Its Macro "ExcelRangeToPowerPoint"which need to add slides for every loop of Macro "Addnumber"

Please Support

Sub AddNumber()

Dim Ws As Worksheet
Dim rngSel As Range
Dim rng As Range
Dim Num As Double
Dim i As Long
Dim j As Long
Dim lAreas As Long
Dim lRows As Long
Dim lCols As Long
Dim Arr() As Variant
Set rngSel = Worksheets("Sheet1").Range("A5:A30")

Do Until Range("A30") = Range("A3")
Num = 26

For Each rng In rngSel.Areas
  If rng.Count = 1 Then
     rng = rng + Num
  Else
      lRows = rng.Rows.Count
      lCols = rng.Columns.Count
      Arr = rng
      For i = 1 To lRows
         For j = 1 To lCols
            Arr(i, j) = Arr(i, j) + Num
         Next j
      Next i
      rng.Value = Arr
  End If
Call ExcelRangeToPowerPoint

Next rng

Loop

End Sub

Sub ExcelRangeToPowerPoint()

'PURPOSE: Copy/Paste An Excel Range Into a New PowerPoint Presentation


Dim rng As Range
Dim rng2 As Range
Dim PowerPointApp As Object
Dim myPresentation As Object
Dim mySlide As Object
Dim myShape As Object
Dim mySize As PageSetup
Dim Addtitle As Shape
Dim DateT As String



'Copy Range from Excel
  Set rng = Worksheets("Sheet1").Range("E2:M30")
  Set rng2 = Worksheets("Sheet1").Range("F2")
  Set rng3 = Worksheets("Sheet1").Range("B3")
'Create an Instance of PowerPoint
  On Error Resume Next
'Is PowerPoint already opened?
  Set PowerPointApp = GetObject(class:="PowerPoint.Application")
'Clear the error between errors
  Err.Clear
'If PowerPoint is not already open then open PowerPoint
  If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(class:="PowerPoint.Application")
'Handle if the PowerPoint Application is not found
      If Err.Number = 429 Then
        MsgBox "PowerPoint could not be found, aborting."
        Exit Sub
      End If
   On Error GoTo 0

'Optimize Code
  Application.ScreenUpdating = False
'Create a New Presentation
  Set myPresentation = PowerPointApp.Presentations.Add
'Add a slide to the Presentation
  Set mySlide = myPresentation.Slides.Add(1, 11)
'11 = ppLayoutTitleOnly

  'Change Theme and Layout
  mySlide.ApplyTheme "C:\Users\davinder.sond\AppData\Roaming\Microsoft\Templates\Document Themes\DefaultTheme.thmx"
  myPresentation.PageSetup.SlideSize = 3
  myPresentation.Slides(1).Shapes.Title.TextFrame.TextRange.Text = rng2
  myPresentation.Slides(1).Shapes.Title.Left = 59
  myPresentation.Slides(1).Shapes.Title.Top = 10
  myPresentation.Slides(1).Shapes.Title.Height = 30
  myPresentation.Slides(1).Shapes.Title.Width = 673

  With myPresentation.Slides(1).Shapes.Title

     With .TextFrame.TextRange.Font
    .Size = 24
    .Name = "Arial"
    .Bold = True
    .Color.RGB = RGB(255, 255, 255)

     End With

    End With

'Copy Excel Range
  rng.Copy

'Paste to PowerPoint and position
  mySlide.Shapes.PasteSpecial DataType:=2  '2 = ppPasteEnhancedMetafile
  Set myShape = mySlide.Shapes(mySlide.Shapes.Count)

    'Set position:
      myShape.LockAspectRatio = 0

      myShape.Left = 12
      myShape.Top = 55
      myShape.Height = 475
      myShape.Width = 756

'Make PowerPoint Visible and Active
  PowerPointApp.Visible = True
  PowerPointApp.Activate

DateT = Format("h:mm:ss")


'Clear The Clipboard
  Application.CutCopyMode = False

 myPresentation.SaveAs "C:\Project Control CCJV\ExperimentsPunch\"& rng3 & ".pptm"

PowerPointApp.Quit




End Sub

Reading a value from cell and searching for that value it in the different Excel cells

$
0
0

I wrote this function that takes a value of one cell and looks for it in another cell (in a different sheet):

Sub FindJobnRow() 
Dim TempTargetRow As Variant

TargetRow = vbNullString
JobNo = vbNullString
JobNo = Worksheets("Working").Range("B1:B1").Value
MsgBox (JobNo)

Set TempTargetRow = Worksheets("Planas").Range("C:C").Find(what:=**JobNo**, Lookat:=xlWhole)
If Not TempTargetRow Is Nothing Then
TargetRow = TempTargetRow.Row
Else
MsgBox (JobNo & "Not Found")
End If

Set TempTargetRow = Nothing
End Sub

Value is being read from a cell and stored in JobNo as a string (declared as program/module wide). The code won't find the value, but if I type in the value instead of variable it works:

Set TempTargetRow = Worksheets("Planas").Range("C:C").Find(what:=**19569**, Lookat:=xlWhole)

I guess it is some whitespaces problem, but Trim() does not seem do be helping.

Bold Top 50% of summed values & Values => 50,000

$
0
0
Sub Highlight_Top50_AND_50K()
    Dim CheckRange As Range
    With ActiveSheet
        Set CheckRange = .Range("E2:E"& .Cells(.Rows.Count, "E").End(xlUp).Row)
    End With

    With CheckRange
        .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual, Formula1:="=0.5*SUM(E:E)", Formula2:="=50,000"
        .FormatConditions(.FormatConditions.Count).SetFirstPriority
        With .FormatConditions(1)
            .Font.Bold = True
            .StopIfTrue = False
        End With
    End With
End Sub

Within Range (E2:E),

CONDITION 1: Bold values that are greater than and equal to 50% of the summed values.

CONDITION 2: Bold values that are greater than and equal to 50,000.

The codes ran without error but nothing is generated. Could someone please enlighten me?

PowerBI: Tooltip using Date/Time and information

$
0
0

I hope that some of you are familiar with Tooltips in PowerBI and their purpose. Therefore, I would like to ask if it is possible to make a tooltip from the data that I copied down here?!

Lets say that I have one set of data (report) where you got exactly the same data format (date/time/info), but their saved in .txt and what I actually wanna is somehow "make" them to work on my charts for that given date/time? I am only able to hover over some data and see whole bunch of data but not exactly for that period (I cant even scroll when the data are just showed in PBI Tooltip).

I managed to extract the date and time using PowerQuery Editor in PBI, but the info part stayed questionable, how or is it possible at all to combine it somehow so I can use it as great tooltip which can say for instance; "okay, on that date you changed system, what is actually visible from the chart", but I would like to have it originally from the "report" aka. tooltip!

Hope you got my question, just wandering if that is possible to do in PBI?

Thx

2019-01-09|13:18:59|Operation Mode C1->C2                                                                  |
2019-01-09|13:19:22|User logged out: ACC2                                                                  |
2019-01-09|13:19:28|User logged in: ACC2                                                                   |
2019-01-09|13:19:31|User logged out: ACC2                                                                  |

here are two photos of what I actually see: enter image description here

and something I wanna see: enter image description here

I did this by excluding the line from the Tooltip, but that isnt efficient at all, because there are thousands of lines

Using Excel Macros to Search on Website If Word Exist or not

$
0
0

I am having an excel sheet with A1-A200 URL's. Since I am newbie in macros, I would like to ask if there is a macros which opens the website with in excel (Not opening in browser) and search for the sentence for example: "there is an error" if the word exist return with "Yes" in B1 otherwise No.

Thanks in advance. Your help will be appreciated.

Print Text File to Excel Sheet

$
0
0

I have a text File named "amk.txt" which looks inside like:

enter image description here

I need to print the content to Excel by using VBA. I have a Function to read the content of the file and to save the content into an Array. The Array looks inside like this:

enter image description here

My Problem is, that the array which saves the fileContent does not look like the inside of txt file. Do you know how I can solve this?


PowerShell 6 doesn't find Excel Interop. PowerShell 5.1 does

$
0
0

In order to use constants from the xlFileFormat enum, I used

[reflection.assembly]::LoadWithPartialName("Microsoft.Office.InterOp.Excel")

In the PowerShell 5.1 it works. Now I do transition to PowerShell 6. The same line issues the error message:

Exception calling "LoadWithPartialName" with "1" argument(s): "Could not load file or assembly 'Microsoft.Office.InterOp.Excel, Culture=neutral, PublicKeyToken=null'. Operation is not supported."

Calling Add-Type instead, I get an error too:

Add-Type -AssemblyName "Microsoft.Office.Interop.Excel"

Add-Type : Cannot find path 'C:\transform\software\Microsoft.Office.Interop.Excel.dll' because it does not exist.

How can I load the Interop DLL installed with the Office?

Return Relative Cell Reference in VBA

$
0
0

I've been looking up some things on the Address function, but whenever it is called on a specific range of cells I get the absolute cell reference value instead of the relative cell reference.

I'm wondering if there's a way to return it without the '$'. I'm used to the ADDRESS formula, but haven't used it's VBA equivalent before. Is there a way to give the function a reference type like you can with the formula?

converting a twitter date string into a datetime field in excel

$
0
0

I have a number of excel strings in the format "Mon Nov 25 17:20:47 +0000 2019"

I found an earlier post that recommended using =DATE(RIGHT(O2,4),MONTH(DATEVALUE(1 & MID(O2,5,3))),MID(O2,9,2)) to create a usable date field. However, this drops the time which is an important piece of information.

How can I include the time with the date in order for excel to recognize and sort all the information included in the field?

Thank you in advance!

DataGridViewS export to excell sheetS

$
0
0

I want to export all my DataGridViews in one Excell document. For every DataGridView there shoud be a own sheet in the Excell File.

But with my code i only recive the Error: System.Runtime.InteropServices.COMException: HRESULT: 0x800A03EC"

I think there is something wrong with my parameters.

        private void exportToExcellButton_Click(object sender, EventArgs e)
    {
        SaveFileDialog saveFileD = new SaveFileDialog();
        string fileName = truckListBox.SelectedItem.ToString() + "__" + DateTime.Now.ToShortDateString();
        saveFileD.InitialDirectory = @"C:/TML/";
        saveFileD.FileName = fileName;

        if (!Directory.Exists(@"C:/TML/"))

            Directory.CreateDirectory(@"C:/TML/");

        List<DataGridView> dataGridViews = getAllDataGridViews();

        Microsoft.Office.Interop.Excel.Application app;
        Microsoft.Office.Interop.Excel.Workbook book;
        Microsoft.Office.Interop.Excel.Worksheet sheet;

        app = new Excel.Application();
        app.Visible = true;
        book = app.Workbooks.Add(System.Reflection.Missing.Value);

        foreach (var grid in dataGridViews)
        {
          int count = book.Worksheets.Count;
          sheet = (Worksheet)book.Sheets.Add(Type.Missing, book.Worksheets[count], Type.Missing, Type.Missing);
            sheet.Name = grid.Name.ToString().Remove(0, 13);

            int cMin = 0, rMin = 0;
            int c = cMin, r = rMin;

            // Set Headers
            foreach (DataGridViewColumn column in grid.Columns)
            {
            //Here appears the Error: System.Runtime.InteropServices.COMException: HRESULT: 0x800A03EC"
                sheet.Cells[r, c] = column.HeaderText;
                c++;
            }

            sheet.Range[sheet.Cells[r, cMin], sheet.Cells[r, c]].Font.Bold = true;
            sheet.Range[sheet.Cells[r, cMin], sheet.Cells[r, c]].VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;

            // Set Rows
            foreach (DataGridViewRow row in grid.Rows)
            {
                r++;
                c = cMin;
                // Set Cells
                foreach (DataGridViewCell item in row.Cells)
                {
                    sheet.Cells[r, c++] = item.Value;
                }
            }
        }
        book.Save();
        book.Close();
        app.Quit();
    }

Spended allready days into it and cant get it work. Thx for your Help!

EDIT: Fixed one error to get to the new one.

Trying to autofilter in Excel using VBA?

$
0
0

I am working on a project that requires me to be able to filter information easily in Excel. I have created lists using data validation, and I am trying to use VBA code to automatically filter the information when those drop down lists are selected.

Every time I try to run the problem, it says there's an error. It points to this code:

Option Explicit

Sub AdvFilt() 'Excel VBA to run the Advanced Filter.
Dim rng As Range
Set rng = Range("B13", Range("U"& Rows.Count).End(xlUp))

    rng.AdvancedFilter 1, [D4:K6], 0
End Sub

I'm very new to VBA and was using this as a guide: https://www.thesmallman.com/blog/2016/9/15/advanced-filter-a-list-automatically

Not sure what I'm doing wrong.

Viewing all 89171 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>