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

Builtinproperties - error on reading fromthe 13th to the last property

$
0
0

I'm trying to extract Metadata from my Excel files. I have files saved in xls (old office versions), xlsx and xlsxm (last office version).I used the example written at https://docs.microsoft.com/en-us/office/vba/api/excel.workbook.builtindocumentproperties:

 rw = 1  Worksheets(1).Activate  For Each p In ActiveWorkbook.BuiltinDocumentProperties      Cells(rw, 1).Value = p.Name      rw = rw + 1  Next

It run perfectly.Then and I added only a line:

 rw = 1  Worksheets(1).Activate  For Each p In ActiveWorkbook.BuiltinDocumentProperties      Cells(rw, 1).Value = p.Name      Cells(rw, 2).Value  ActiveWorkbook.BuiltinDocumentProperties(p.Name)     rw = rw + 1  Next

It runs till the 12th property (Last Save Time), then it shows me an error for the following properties.May you help me please?


OLEDB Update Query fails to update .xlsm file

$
0
0

i'm trying to update an already open macro file (.xlsm) using update Query. the Update Query updates the the macro sheet sometimes but misses to update the sheet in some cases where there is no error appearing in this case.

My connection strig:

connstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="& dbpath & ";Extended Properties=""Excel 12.0 Macro;HDR=YES"";"

Update Query:

strSQL = "UPDATE ["& QuerySheet & "] SET [Alias]= '"& Alias &"',[Tolerable Error]= '"& TE & "', [Account Type]= '"& AccountTypeList & "',[Account Sub-Type]= '"& AccountSubTypeList &"',[Account Class]= '"& AccountClassCheckbox & "' ,[Account Sub-Class]= '"& AccountSubClassCheckbox & "',[GL Accounts]= '"& GLAccountsCheckbox & "',[Scoping Dropdown Selection]= '"& ComboBoxSelectedValue & "',[Account Type (ALL)]='"& AccountTypeList &"',[Account Sub-type (ALL)]='"& AccountSubTypeList & "',[Account Class (ALL)]='"& AccountClassList & "',[Account Sub-class (ALL)]='"& AccountSubClassList & "',[GL Accounts (ALL)]='"& GLAccountList & "' Where [Category Name]= '"& PrimaryStatement & "' AND [Group]='"& GroupCounter & "'"

 strSQL = "UPDATE ["& QuerySheet & "] SET [Alias]= '"& Alias & "',[Tolerable Error]= '"& TE & "', [Account Type]= '"& AccountTypeList & "',[Account Sub-Type]= '"& AccountSubTypeList & "',[Account Class]= '"& AccountClassCheckbox & "' ,[Account Sub-Class]= '"& AccountSubClassCheckbox & "',[GL Accounts]= '"& GLAccountsCheckbox & "',[Scoping Dropdown Selection]= '"& ComboBoxSelectedValue & "',[Account Type (ALL)]='"& AccountTypeList & "',[Account Sub-type (ALL)]='"& AccountSubTypeList & "',[Account Class (ALL)]='"& AccountClassList & "',[Account Sub-class (ALL)]='"& AccountSubClassList & "',[GL Accounts (ALL)]='"& GLAccountList & "' Where [Category Name]= '"& PrimaryStatement & "' AND [Group]='"& GroupCounter & "'"

Upon using line cellRange.Value = "00:00" the code stops [duplicate]

$
0
0

I have a excel spreadsheet that records working hours per day. I've written some VBA that upon a cell (D10) containing "Rest Day" it:

  • a. Sets the cells (E10:F10) to a different colour
  • b. Sets the cells (E10:F10) to Read Only
  • c. Sets the contents of the cells (E10:F10) to "00:00"

The code works but upon running the line "cellRange.Value = "00:00" the code drops out and any other code below that line is not processed - most crucially the line "ActiveSheet.Protect ("test")"

The code is as follows:

Private Sub Worksheet_Change(ByVal Target As Range)If [D10] = "Rest Day" Then ActiveSheet.Unprotect ("test")[E10].Interior.ColorIndex = 34[F10].Interior.ColorIndex = 34[E10].Locked = True[F10].Locked = True    Dim cellRange As Range    Set cellRange = Range("E10:F10")    cellRange.Value = "00:00"ActiveSheet.Protect ("test")ElseActiveSheet.Unprotect ("test")[E10].Interior.ColorIndex = 0[F10].Interior.ColorIndex = 0[E10].Locked = False[F10].Locked = False'Next line is optional, remove preceding apostrophe if protection should stay on.ActiveSheet.Protect ("test")End IfEnd Sub

Any help would be greatly appreciated.

Nigel.

When a value is writing (X2) I need a pop up text box to write the value to the next cell [closed]

$
0
0

I am going to explain with the example, I think it is easier.What I need is a macro to run and analyze columns F, I, L, O, and so on and when I write X2, a pop up text box appears.On that pop up text box I should be asked "How many hours I want to enter" and that value is added to the cell on the right. For instance, when I write X2 in cell I9, and write 8 on the pop up, the number 8 should be entered at J9...

example

Replace YYYY in all series name across charts and multiple worksheets

$
0
0

I am trying to change all the data (in YYYY) in my charts from 'XX-2019' to 'XX-2020'.

I'm trying to replace all '2019' with '2020', but I can't seem to get the code below to work. Is there something that I am missing with the FullSeriesCollection usage?

Sub ChartLabelReplace()Dim xWs As WorksheetDim xFindStr As StringDim xReplace As StringxFindStr = Application.InputBox("Find:", xTitleId, "", Type:=2)xReplace = Application.InputBox("Replace:", xTitleId, "", Type:=2)Set xWs = Application.ActiveSheetFor Each ch In xWs.ChartObjects    If ch.Chart.HasLegend Then        ch.Chart.FullSeriesCollection.Name = VBA.Replace(ch.Chart.FullSeriesCollection.Name, xFindStr, xReplace, 1)    End IfNextEnd Sub

VBA DOM getElementsBy can't get childnodes

$
0
0

I'm trying to get the innertext of a label but i'm getting an error. Through the console i'm succesfully getting the inner text with this script :

document.getElementsByClassName("item alt")[0].childNodes[2].childNodes[0].innerText

Element i'm trying to get :

<tr class="item alt" data-id="1376936"><td class="toolbar left"><a href="#" class="show-incidents button-small ui-state-transparent-default rc" title="Details"><span class="ui-icon ui-icon-triangle-1-e"></span></a></td><td class="time">14:00</td><td class="status"><span class="status-1 rc">FT</span>

My VBA script :

Sub WebScraping()    Dim ie As InternetExplorer    Dim html As HTMLDocument    Set ie = New InternetExplorer    ie.Visible = True    ie.navigate "https://www.whoscored.com/Regions/74/Tournaments/22/Seasons/7814/Stages/17593/Fixtures/France-Ligue-1-2019-2020"    Do While ie.readyState <> READYSTATE_COMPLETE    Application.StatusBar = "Trying to go to Whoscored ..."    DoEvents    Loop    Set doc = ie.document    Do While ie.readyState <> READYSTATE_COMPLETE    Application.StatusBar = "Trying to go to Whoscored ..."    DoEvents    Loop    Set a = doc.getElementsByClassName("item alt")(0).ChildNodes(2).ChildNodes(0).innerText    MsgBox (a)End Sub

SUBTOTAL where dates are between a range

$
0
0

im doing some calculations in excel and noticed there were way off what i was expecting i was using this formula calculate the sum for values between a date range:

=SUMIFS(V496:V57573,U496:U57573,">"&"01/01/2020",U496:U57573,"<"&"29/02/2020")

i think i should be using the SUBTOTAL to do it on the filtered data so i get the result for that subset. How would i use the subtotal to have it where its in that date range on an already filtered data set

Remove the word 'The' from the front of a company name to the end of the company name in Excel, is there a simple formula?

$
0
0

I have been trying for a couple of hours to figure out how I can remove the word #The' from the front of a company name, then add it back at the end of the company name, I have tried various things without luck.

I hope you can help.

I need to change it from The Excel Team, to Excel Team, The

Or is there a way to sort my list on excel discounting the word 'The'

Thanks in advance.


I need advise on the code below written to prevent paste on the drop down cells

$
0
0

I'm new to VBA. Here's the code

  Private Sub Worksheet_Change(ByVal Target As Range)'Does the validation range still have validation?   If HasValidation(Range("DataValidationRange")) Then       Exit Sub   Else       Application.Undo       MsgBox "Error: You cannot paste data into these cells."& _"Please use the drop-down to enter data instead.", vbCritical   End IfEnd Sub``Private Function HasValidation(r) As Boolean'Returns True if every cell in Range r uses Data Validation   On Error Resume Next   x = r.Validation.Type   If Err.Number = 0 Then HasValidation = True Else HasValidation = FalseEnd Function

How is that possible that the line "If HasValidation(Range("DataValidationRange")) Then" returns false if DataValidationRange obciously has data validation, which means 'exit sub' should be executed. But apparently reutrn value is false because sub works correctly which makes me wonder how that line works. What am I missing?

Moving on Numbers and Calculating results Automatically [closed]

$
0
0

EDITED

I have this project I'm working on Excel.

enter image description here

I need to check a set of numbers (exceeding 3k), to find out which of them that produces the highest counts of 3, 6 and 9 as a digital root of the results.

I do that by replacing the Main number in the main cell (432).

the Results are produced by set of formulas arranged in the file. Results

I arrange the numbers I want to check in excel cell vertically

enter image description here

I keep checking each numbers one after the other. and check the digital root of the results results...

enter image description here

and then use the countif function to check how many 3,6 and 9 were produced as a digital root for all the results. (I Sum them together)

enter image description here

is there a way that can move on the numbers in the vertical list automatically? to replace them one by one in the cell of Main Number?

then copy the sum of 3+6+9 into the cell beside it?

here is the file for better understanding.

thank you in advance

https://drive.google.com/drive/folders/1zcvGmmlbWR6AOKQv4ZTmfQjwJXbPMBIm?usp=sharing

Open Excel file from URL in javascript

$
0
0

I want to open Excel File from javascript

I am trying below code, it is opening the Excel file but the content is not correct as file is getting opened as [ReadOnly].

window.open('ms-excel:ofe|u|http://some-host-name.com/filestest.xlsx');Can I open the file without [ReadOnly] using similar code?

Copy/Paste columns

$
0
0

I have several columns with headers in one excel workbook, I want to copy some of these columns into another workbook.

Let’s say I have my origin workbook:

Ident|Name|Code|Part|Desc|U|Total

These are the headers of the columns with some data below them.

And I want to copy only the data in the columns Ident, Code and Part in another workbook that has the same headers but in a different order with the exception that one header has a different name:

Code|Ident|Piece

It is blank and Piece corresponds to Part. So I want a code that takes the data from the origin workbook and copy it to the destination workbook. Also if possible I’d like that you can choose the original workbook from a file as I have different excel files to choose from.

Thank you for your answers. I have never used VBA and I’m trying to learn.

I have the following code that lets you choose the data you want manually but I want something similar that does it automatically after recognizing the headers.

Sub ImportDatafromotherworksheet()Dim wkbCrntWorkBook As WorkbookDim wkbSourceBook As WorkbookDim rngSourceRange As RangeDim rngDestination As RangeSet wkbCrntWorkBook = ActiveWorkbookWith Application.FileDialog(msoFileDialogOpen)    .Filters.Clear    .Filters.Add "Excel 2007-13", "*.xlsx; *.xlsm; *.xlsa"    .AllowMultiSelect = False    .Show    If .SelectedItems.Count > 0 Then        Workbooks.Open .SelectedItems(1)        Set wkbSourceBook = ActiveWorkbook        Set rngSourceRange = Application.InputBox(prompt:="Select source range", Title:="Source Range", Default:="A1", Type:=8)        wkbCrntWorkBook.Activate        Set rngDestination = Application.InputBox(prompt:="Select destination cell", Title:="Select Destination", Default:="A1", Type:=8)        rngSourceRange.Copy rngDestination        rngDestination.CurrentRegion.EntireColumn.AutoFit        wkbSourceBook.Close False    End IfEnd WithEnd Sub

Co-authoring when using WorkBook Settings/CustomProperties

$
0
0

I've been looking for any documentation which suggests whether there is a way of saving Document Settings & CustomProperties such that they're automatically propagated to co-authors of the current document.

I've done some testing which suggests that's these settings aren't automatically propagated even when the document is saved. I'm also storing XML inside the document so I'm concerned that this won't be propagated as well. Since I'm doing this in Excel, I could always create a hidden sheet to store the properties in and have a watch on the table (or some similar set-up) but this isn't really the avenue I want to go down since some user could easily come along and delete the hidden sheet or manipulate its contents.

Has anyone come across this issue and managed to find a solution to it?

Sumifs several sheets

$
0
0

I am trying to sum up all numbers using three criteria:

Criterion 1: Person A, B or CCriterion 2: HeadCriterion 3: FTE

Here is my Uerbesicht or overview sheet, where I would like to have my code to inset sumif formula with the above three criteria:

enter image description here

This is the sheet 1, as an example, which I am counting.

enter image description here

This is my code

Dim m As Stringm = "a;b;c"Dim uebersicht As Worksheet    Set uebersicht = ActiveSheet    Dim i As Integer  For m = "a" To "c"    For i = 1 To 8        For j = 4 To 6 'column number            For k = 2 To 17 'row number        uebersicht.Cells(j, k).Value = Application.WorksheetFunction.SumIfs(Sheets(i).Range("B2:B4"), Sheets(i).Range("A2:A4"), m)            Next k        Next j    Next i  Next m

My code is not working. I appreciate your help.

Open Email Attachments File

$
0
0

I have open attachments file using following code

Sub Test()Dim path As StringDim msgFile As Stringpath = Application.ActiveWorkbook.path +"\"file = path & "\*.msg"Dim OutApp As Outlook.ApplicationDim OutMail As Outlook.mailitemSet OutApp = CreateObject("Outlook.Application")Set OutMail = OutApp.CreateItemFromTemplate(file)On Error Resume NextWith OutMail    .To = Application.User    .SendEnd WithOn Error GoTo 0Set OutMail = NothingSet OutApp = NothingEnd Sub

But

Email attachments file was not open.

How to Open Email Attachments File in Macro?


substitute expression not only based on the cell value, but also on the formatting [closed]

$
0
0

I want to write a small translator programme and I tried different approaches so far, but always got stuck at some point.

First I will give a small description of my programme and then I will tell you what has been my main difficulty so far.

enter image description here

The attached image shows the interface of my programme.It should work as follows. The user types a list of sequences of coding symbols in the A column.Triggered by a button click the programme then translates these sequences from code1 to the other three codes. The translation is based on the table on the right. For a better understanding I translated the first row myself to give an example. I want to create a sheet for each of the four codes with which the code can be translated to the three other codes (but after getting how to do it for 1 code, the other 3 should not be a problem anymore).

Here is what I tried so far:

I loop though the given sequence, looking for the longest coding symbols first and substituting them by the according symbols of the three other codes given in the table (using the substitute command). I treated the input from the user at column A as string variables. My main problem is that I cannot find an efficient way to discriminate between the different formats of the inputs in column A (subscript, superscript and different colors of text). So if for example I want to translate from Code3, I get stuck while translating from red "B", because the substitute command cannot discriminate it from a "B" written in black.

I would be super happy about any ideas how to overcome this problem. Thanks already for your support!

C# EPPlus get value of formula cell

$
0
0

I have a simple formula in a number of cells and I'm trying to get the result of that formula into a variable in my program. My inital code was:
var ECC = ws.Cells["B14"].Value;decimal ECP = Convert.ToDecimal(ECC);
but this got me an error "System.InvalidCastException: 'Unable to cast object of type 'OfficeOpenXml.ExcelErrorValue' to type 'System.IConvertible'.'"I tried calculating and adding a toString, making my code:
ws.Cells["B14"].Calculate();decimal ECP = Convert.ToDecimal(ws.Cells["B14"].Value.ToString());
This got me a different error: "System.FormatException: 'Input string was not in a correct format.'" on the second line.

The result of the formula will always be a decimal and it's important that I get it into a decimal variable because I'm putting that value into a SQL database. How can I do this error-free?

C# EPPlus merge Excel Files

$
0
0

I want to merge multiple Excel files with EPPlus in C#.

I did the following:

using (MemoryStream protocolStream = new MemoryStream()){    ExcelPackage pck = new ExcelPackage();    HashSet<string> wsNames = new HashSet<string>();    foreach (var file in files)    {        ExcelPackage copyPck = new ExcelPackage(new FileInfo(file));        foreach (var ws in copyPck.Workbook.Worksheets)        {            string name = ws.Name;            int i = 1;            while (!wsNames.Add(ws.Name))                name = ws.Name + i++;            ws.Name = name;            var copiedws = pck.Workbook.Worksheets.Add(name);            copiedws.WorksheetXml.LoadXml(ws.WorksheetXml.DocumentElement.OuterXml);        }    }    pck.SaveAs(protocolStream);    protocolStream.Position = 0;    using (FileStream fs = new FileStream(resultFile, FileMode.Create))        protocolStream.CopyTo(fs);}

But I get the following error in pck.SaveAs(protocolStream):

System.ArgumentOutOfRangeException

in System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) in System.Collections.Generic.List1.get_Item(Int32 index) in OfficeOpenXml.ExcelStyleCollection1.get_Item(Int32 PositionID)

I also tried it with the Worksheet.Copy method, but I lose the styling with it.

Attempt to create a macro in excel that controls the out put of a cell based on the value of other cells in the row

$
0
0

Example of the fileI have been trying to learn VBA to write a code to create a macro to help me get an output cell depending on many conditions in other cells.So what I want is to fill each cell in column M based on other parameters in the same row of that cell depending on different level of priority:

1- if the cell in Column J is not "PASS" then I want the corresponding cell in M column to show whatever is in J other than "PASS".

2- if the cell in column J is "PASS" then the corresponding cell in column M will depend whether the cell in column I is "NO ANOMALY DETECTED" or anything else. If it's anything else then make the cell in column M whatever is in column I. Otherwise if it is "NO ANOMALY DETECTED" then make the value of the cell in column M similar to that in column G but replacing "NO ANOMALY DETECTED - " by "Euploid, " and keep XY or XX.

I also tried colouring based on value.:The code I used:

Sub QC()If Range("J2:J98").Value <> PASS Then Range("M2:M98").Value = Range("J2:J98")End IfSub Abnormality()If Range("J2:J98").Value = PASS and Range("I2:I98").Value <> "NO ANOMALY DETECTED" Then Range("M2:M98").Value = Range("I2:I98") and cell.Interior.Color = vbRedEnd IfSub Euploid_Sex()If Range("J2:J98").Value = PASS and Range("I2:I98").Value = "NO ANOMALY DETECTED" and Range("G2:G98").Value = "NO ANOMALY DETECTED - XY" Then Range("M2:M98").Value = "Euploid, XY"ElseIf Range("J2:J98").Value = PASS and Range("I2:I98").Value = "NO ANOMALY DETECTED" and Range("G2:G98").Value = "NO ANOMALY DETECTED - XX" Then Range("M2:M98").Value = "Euploid, XX"End IFSub Result_Coulour()IF Range("M2:M98").Value = "Euploid, XY" then Range ("M2:M98").Font.Color - RGB(0, 176, 240)ElseIf Range("M2:M98").Value = "Euploid, XX" then Range ("M2:M98").Font.Color - RGB(255, 153, 255)End IF

Powershell Excel Master Spreadsheet

$
0
0

This is a long winded one but I will try and shorten it.

I have a master spreadsheet exported from our MIS system each school term and it gives me all the classes and who is in them for a specific school year.

The only problem is that it comes as one massive sheet within one workbook.

It looks like this:

Redacted Master Sheet Image

My end goal is to have one master workbook with each class cut and pasted into a separate sheet, and then the name of that sheet is the 'class code' which is the {redacted} part at the top of each section.

This has been done manually until now but it takes hours.

Is there a way in powershell to do this? I need the data from Class List Report: ... to Males: X Females: X into their own sheet within the workbook and then name the sheet the class code. Unfortunately the classes are different lengths so I cant do it based on counting the number of cells.

Any help is greatly appreciated.

Viewing all 87999 articles
Browse latest View live


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