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

How To remove #NA from Excel Range in C#

$
0
0

I have been trying to figure this out for a while now. But solutions like this and this are not solving my problem.

I'm adding data from Database to Excel with the following code :-

//Adding Table values in Excel
            int sum = 0;
            object[,] arr = new object[result.Rows.Count, result.Columns.Count];
            for (int r = 0; r < result.Rows.Count; r++)
            {
                DataRow dr = result.Rows[r];
                for (int c = 0; c < result.Columns.Count; c++)
                {
                    arr[r, c] = dr[c];
                }
                    sum = sum + Convert.ToInt32(dr[5]);
            }


            Microsoft.Office.Interop.Excel.Range c3 = (Microsoft.Office.Interop.Excel.Range)ws.Cells[20, 1];
            Microsoft.Office.Interop.Excel.Range c4 = (Microsoft.Office.Interop.Excel.Range)ws.Cells[result.Rows.Count + 20, result.Columns.Count];

            Microsoft.Office.Interop.Excel.Range range1 = ws.get_Range(c3, c4);
            range1.Value = arr;

Now on the line range1.Value = arr; it is adding another row with all columns value as #N/A when I debug the code the value shown there is -2146826246.

First, I don't understand why is it adding a row of it's own at the end? Second, why the values are coming as #N/A and how to resolve this?


Excel/Outlook: how do you access multiple shared inboxes?

$
0
0

I've managed to retrieve mails from the shared inbox using the following code

   Sub GetFromOutlook()
    Dim OutlookApp As Outlook.Application
    Dim oaccount As Outlook.Account
    Dim OutlookNamespace As Namespace
    Dim ostore As Outlook.Store
    Dim Folder As MAPIFolder
    Dim OutlookMail As Variant
    Dim i As Integer   
    MailBoxName = "support@company.com"
    Set OutlookApp1 = New Outlook.Application
    Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")

    Set objOwner = OutlookNamespace.CreateRecipient(accName)
    objOwner.Resolve

    If objOwner.Resolved Then
        Set Folder = OutlookNamespace.GetSharedDefaultFolder(objOwner, olFolderInbox).Folders("IL").Folders("5")

However, when I try to change the MailBoxName = "support@company.com" to "sales@company.com" later on in the code, I get the following error:

Run-time error -2147221219 (8004011d)
The operation failed because of a registry or installation problem. Restart Outlook andtry again.If the problem persists, reinstall.

It is if like Excel/Outlook remembers the connection. Can someone help with this problem?

Inserting row and copying only certain formulas from above

$
0
0

I am working on a project which includes a sheet that will look broadly similar to the the one in the linked picture, see example picture.

I want to work with a set of macro buttons that adds a row above the integers in column B. For example, if I press "Button 1", I want to add a row after the last row in section 1, i.e. between 1.5 and 2. When I do this, I also wish to copy the formulas from a range of cells above.

I have tried various codes but cannot seem to get this to work. In the linked picture, the cells containing formulas from which i want to copy has been highlighted in yellow.

The code below works fine but the only problem now is that I don't know how to define "iRow" so that it always refer to the row which contains the value 2.

Sub BlankLineSales()

Dim Col As Variant
Dim BlankRows As Long
Dim LastRow As Long
Dim R As Long
Dim StartRow As Long

    Col = "B"
    StartRow = 1
    BlankRows = 1

        LastRow = Cells(Rows.Count, Col).End(xlUp).Row

        Application.ScreenUpdating = False

        With ActiveSheet
  For R = LastRow To StartRow + 1 Step -1
  If .Cells(R, Col) = "2" Then
  .Cells(R, Col).EntireRow.Insert Shift:=xlDown

 End If
 Next R
 End With
 Application.ScreenUpdating = True

Dim iRow As Long
     **iRow = ??????**
  'Select row
Rows(iRow - 1).Select
Selection.Copy

 'Paste it into the new row
Rows(iRow).Select
Selection.PasteSpecial Paste:=xlPasteFormulas

Application.CutCopyMode = False

End Sub

I appreciate any advice on this matter. Thanks.

GoTo is not defined - in VBA

$
0
0

When I on the step F8 click. then say it Goto is not defined. I try to make a inputbox with a messagebox that me the answer give. And I try also to make code when the values not correct is. See, you where I make a mistake in my VBA code:

Sub TwoNumbersinputbox()

Dim bytAnswer1 As String
Dim bytAntwer2 As String
Dim Range As Byte
Dim strNumber1 As String
Dim strNumber2 As String
[C3] = "Number1"
[C4] = "Number2"

Start1:
strNumber1 = InputBox("Give number one?", "Invoer", 5, 567, 567)
   If IsNumeric(strNumber1) Then
   MsgBox "This must be Number1", vbCritical, _
   "Number1 input"
   GoTo strNumber1
   Else: [B2] = strNumber1
   End If

  If Not IsNumeric(strNumber1) Then
  MsgBox "there is error.", vbCritical, "Number2 input"
  bytAnwer1 = MsgBox("Start Again?", vbYesNo)
  If bytAnwer1 = vbYes Then GoTo Start
  End If

Start2:
strGetal2 = InputBox("Give Number2?", "Input", 5, 567, 567)
   If IsNumeric(strNumber2) Then
   MsgBox "This must be Number2 ", vbCritical, _
   "Number2 input"
   GoTo strNumber2
   Else: [B3] = strNumber2
 End If

  If Not IsNumeric(strGetal2) Then
  MsgBox "Is there an error.", vbCritical, "Number2 input"
  bytAnswer2 = MsgBox("Start Again?", vbYesNo)
  If bytAnswer2 = vbYes Then GoTo Start
  End If

End Sub

Work with DDE Links from Excel to Shiny in R

$
0
0

Guys I have a DDE link that feeds my excel spreadsheet.

This is the DDE Link: NAMEofTheCOMPANY|cot!STOCKA.LAST he hands me the real-time market stock price.

I then paste it to a cell on the excel spreadsheet and works fine.

What I need:

1) With this DDe link in my Excel spreadsheet how do I "send it" to Shiny?

2) How do you work with DDe links? Is there a way I can "send" this link DIRECT to Shiny without having to go through my Excel spreadsheet and then send it to Shiny?

Any help guys

I am a begginer in Shiny.

Many thanks

VBA for google spreadsheets [closed]

$
0
0

I want to convert this Visual Basic Applications script to Google script for use in google spreadsheet:

Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.Address = "$B$3" Then

        Range("B2").Delete
    End If

    If Target.Address = "$D$3" Then

        Range("D2").Delete

    End If

End Sub

Bulk Export/Create CSVs From Excel Files or Using Google Sheets

$
0
0

I need to import approximately 150 network switches into our telecom database. Each network switch must be imported one at a time using a CSV file. The CSV file for import contains two columns of data with 54 rows. Column 1 contains the host name of the switch and Column 2 contains the port numbers. I have a spreadsheet with the 150 network switches and a import template containing the 54 port numbers. My goal is to find a process that will bulk create 150 CSV files using my import template, updating the 54 rows in Column 1 with the switch hostname.

Alternatively, I believe there is the possibility of importing this data all in one CSV file. Then my goal would be to create one CSV file from the import template with 8100 rows (54 ports x 150 switches), 54 rows containing one of the network switch host names, repeating for each network switch.

Based on what I found online so far Python appears to have this capability. However, I’m a bit of a novice when it comes to Python programming. I’m better versed on Google Sheets scripting.

Count unique values based on criteria in 2 other columns in VBA

$
0
0

enter image description here

I have a sheet like:

|   |  A |    B    |   C  |      D     |
|---|:--:|:-------:|:----:|:----------:|
| 1 | ID | Country | Site | Milestones |
| 2 |    |         |      |            |
| 3 |    |         |      |            |

In each ID I can have multiple countries, and for each country, multiple sites and in each site, multiple milestones.

I’m looking to add a column that counts the number of unique sites per country per ID.

I have tried to do this in column E using a formula but I’d prefer this with a VBA loop as it’s part of more code.

I also was not able to account for blanks!

In column f I have what I would have expected. Thanks for help in advance!


Importing Excel data into SQL Server

$
0
0

I have extracted the data from an Excel file into SQL Server Management Studio and tried the below code; however, it seems it is not working. The table (order) on the left side is unknown to the SQL code

use order

select * from order

enter image description here

Is there a way to count the number of characters per word for a string, returning values separated by a comma?

$
0
0

I have a list of strings in cells - 1000s of them - and I need to work out the characters per word but separated by word - preferably in 1 swift formula...

For Example: 1. "Black Cup With Handle"> Formula I need > 5,3,4,6

  1. "Giant Bear Statue"> Formula I need > 5,4,6

I need this for a recurring task which has been macro'd in a very inefficient way to count words into columns (of which we need to use up to 20 for the just encase) but this needs to be tackled.

Usually, we count the spaces and layer nested serach() formulas to piggyback onto one and other to break down the structure then character counts the individual words...

I could alternatively the macro to substitute the spaces for commas and used text to columns but that still leaves me with a prolonged counting process for what im looking for

we obviously use =LEN(A1)-LEN(SUBSTITUTE(A1,"","")) to count the spaces in the word

we currently then use =SEACRH() function combined with =MID() functions (and some bizarre numbers) to reveal each word into its own individual cell

then =LEN once again bu on all individual words - very long-winded

Im hoping to find a shorter way to do this but feeling there may not be a dynamic enough way to do it with formula alone, hoping someone can prove me wrong!

How to get info from the Initials field in the oulook addressbook with excel vba

$
0
0

Dear Stackoverflow community,

I am a clerk and thought myself a litte excel-vba in order to automate some tasks in the office.

However, while "coding" I stumbled upon the problem, that I can't retrieve information stated within the Initials field from the Outlook addressbook with vba. When you click on an entry in the Outlook addressbook, a pop-up window appears with the user information. With vba I could easily access all fields except the Initials field. (Here is the window with the field indicated in red AddressBookInformationJohnDoe.)

One Skript I wrote, extracts information of an employee in my company and copies it in the cells next to the employee's name. (See the simplified code below. Code that obviously does not work is commented out and ends with a question mark.)



Dim olApp           As Outlook.Application
Dim olNS            As Outlook.Namespace
Dim olRecip         As Outlook.Recipient

Dim Cell            As Range
Dim NameEmpl        As String
Dim Company         As String
Dim Initials        As String

NameEmpl = LCase(Trim(ActiveCell.Value))

Set olApp = CreateObject("Outlook.Application")
Set olNS = olApp.GetNamespace("MAPI")

Set olRecip = olNS.CreateRecipient(NameEmpl)
olRecip.Resolve

Company = olRecip.AddressEntry.GetExchangeUser.CompanyName
'Initials = olRecip.AddressEntry.GetExchangeUser.Initials ?

    ActiveCell.Offset(0, 1).Value = Company
    'ActiveCell.Offset(0, 2).Value = Initials ?

End Sub

However, within GetExchangeUser I can't find an object for the initials field. Is there an other way to extract the information?

I have seen similar questions in this forum, but could not quite follow the proposed answers. Therefore, I kindly ask, if anyone of you knows the answer and could explain it to an amateur.

Many thanks. Regards,

questioner

Add rows before the column header using excel.js module + node

$
0
0

I am trying to create xslx file using excel.js module in node.js. I was able to create the columns and add its values. But, I need to insert some rows before the columns headers, where I can have some descriptions. How can I do that?

I need something like this

Any help will be appreciated

The code I tried is

     var worksheet = workbook.getWorksheet(1);
    worksheet.mergeCells('A1:B1');
    var row = worksheet.getRow(1);
    row.getCell(1).value =' Hello, World!'; 
   // ... merged cells are linked 
    worksheet.getCell('A1').value = 'PI';
    worksheet.columns = [
        {header: 'Id', key: 'id', width: 10},
        {header: 'Name', key: 'name', width: 32},
        {header: 'complexity', key: 'complexity', width: 10},
        {header: 'hours', key: 'hours', width: 10},
        {header: 'cost', key: 'cost', width: 10}
    ];
     worksheet.addRow({name:'m', complexity: 'd', hours:5, cost: 7});

User to import XLSM files into Oracle APEX

$
0
0

Is there a way where the user can import XLSM (macro) files?

I'm building an application and the user would have to import their files which are Excel with macros. For this application I would only need certain data from these files, like columns with payment amounts and due dates.

Command Button to copy text from textbox to clipboard doesn't work

$
0
0

I have a userform with a textbox (Textbox1) and Command Button (cmdButton). I got a vba code from youtube, it seems to work in the video, but when I try it, the text in the textbox will not be copied into the clipboard. How can I fix that?

I renamed the CommandButton1 to cmdButton

Private Sub cmdButton_Click()
    Dim strClipBoard As String
    Set objData = New DataObject

    strClipBoard = Textbox1.Text
    objData.SetText strClipBoard
    objData.PutInClipBoard

    objData.GetFromClipboard
    strClipBoard = ""
   strClipBoard = ObjData.GetText
End Sub

Phpspreadsheet - cant download xlsx file

$
0
0

im using macOS and trying phpspreadsheet. If I give permission to folder with project, I can save xlsx file and everything is OK. But if I want to download it, xlsx is broken, the file saying me, that extension does not match with content. If I rename xlsx to xls in xls is this:

<b>Warning</b>:  ZipArchive::close(): Failure to create temporary file: No such file or directory in <b>/Applications/XAMPP/xamppfiles/htdocs/EXPORT_TEST/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php</b> on line <b>409</b><br />
<br />
<b>Fatal error</b>:  Uncaught PhpOffice\PhpSpreadsheet\Writer\Exception: Could not close zip file php://stdout. in /Applications/XAMPP/xamppfiles/htdocs/EXPORT_TEST/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php:410
Stack trace:
#0 /Applications/XAMPP/xamppfiles/htdocs/EXPORT_TEST/test_export_2.php(25): PhpOffice\PhpSpreadsheet\Writer\Xlsx-&gt;save('php://stdout')
#1 {main}
  thrown in <b>/Applications/XAMPP/xamppfiles/htdocs/EXPORT_TEST/vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php</b> on line <b>410</b><br />

I give permission to all subfolders in XAMPP but same problem.

<?php
//call the autoload
require 'vendor/autoload.php';
//load phpspreadsheet class using namespaces
use PhpOffice\PhpSpreadsheet\Spreadsheet;
//call iofactory instead of xlsx writer
use PhpOffice\PhpSpreadsheet\IOFactory;

//make a new spreadsheet object
$spreadsheet = new Spreadsheet();
//get current active sheet (first sheet)
$sheet = $spreadsheet->getActiveSheet();
//set the value of cell a1 to "Hello World!"
$sheet->setCellValue('A1', 'Hello World !');

//set the header first, so the result will be treated as an xlsx file.
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

//make it an attachment so we can define filename
header('Content-Disposition: attachment;filename="result.xlsx"');

//create IOFactory object
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
//save into php output
$writer->save('php://stdout');

Can you give me some advices, what is bad?


How to automatically group all empty rows in excel?

$
0
0

So, I've got some very large excel documents and need a way to automatically group rows. In column A, there will be a room number. The rows below that will have nothing in them, until the next room number. So the empty rows between the room numbers need to be grouped, like shown in the pics in the comments.

Should be pretty simple to make in vba but I'm useless at programming and modifying others similar ones didn't work :(

Hopefully someone can help because I cannot be grouping the multiple thousand rooms manually haha :)

Thanks!

Mismatch error in VBA - problems with columns

$
0
0

I have a workbook where I want to find the differences of two sheets by looking at the company name and their corporate registration number and then type the differences on the third sheet.

I have tried the code in another workbook with only 143 rows, which works perfectly, but when I try it on the real workbook with 10,000 rows I get a "type mismatch error". Also if I use other columns than the CVR and Firm columns the code also works.

The CVR is numbers and Firms are strings (firm names). I get the

type mismatch error

on the line I marked **. Does somebody know why I get this error?

Sub ComCVR()
Dim CVR1()
Dim CVR2()
Dim Firm1()
Dim Firm2()
Dim n As Long, m As Long
Dim i As Double, j As Double
Dim intCurRow1 As Integer, intCurRow2 As Integer
Dim rng As Range, rng1 As Range

Set rng = ThisWorkbook.Sheets("Last month").Range("A11")
Set rng1 = ThisWorkbook.Sheets("Current month").Range("A11")

n = rng.CurrentRegion.Rows.Count
m = rng1.CurrentRegion.Rows.Count

ReDim CVR1(n)
ReDim Firm1(n)
ReDim CVR2(m)
ReDim Firm2(m)

ThisWorkbook.Sheets("CVR").Range("A1") = "Flyttet CVR"
ThisWorkbook.Sheets("CVR").Range("B1") = "Flyttet Firmanavn"
ThisWorkbook.Sheets("CVR").Range("A1:B1").Interior.ColorIndex = 3
ThisWorkbook.Sheets("CVR").Range("C1") = "Nye CVR"
ThisWorkbook.Sheets("CVR").Range("D1") = "Nye Firmanavn"
ThisWorkbook.Sheets("CVR").Range("C1:D1").Interior.ColorIndex = 4
ThisWorkbook.Sheets("CVR").Range("A1:D1").Font.Bold = True

' Inset data to arrays
For i = 0 To n
    CVR1(i) = ThisWorkbook.Sheets("Last month").Cells(12 + i, 5)
    Firm1(i) = ThisWorkbook.Sheets("Last month").Cells(12 + i, 4)
Next

For i = 0 To m
    CVR2(i) = ThisWorkbook.Sheets("Current month").Cells(12 + i, 5)
    Firm2(i) = ThisWorkbook.Sheets("Current month").Cells(12 + i, 4)
Next
intCurRow1 = 2
intCurRow2 = 2

'Old
For i = 0 To n
    For j = 0 To m
        If Firm1(i) = ThisWorkbook.Sheets("Current month").Cells(12 + j, 4) Then  '** Error raised here   
      Exit For
        End If

        If j = m Then
            ThisWorkbook.Sheets("CVR").Cells(intCurRow1, 1) = CVR1(i)
            ThisWorkbook.Sheets("CVR").Cells(intCurRow1, 2) = Firm1(i)
            intCurRow1 = intCurRow1 + 1
        End If
    Next j
Next i

'new
For i = 0 To m
    For j = 0 To n
        If Firm2(i) = ThisWorkbook.Sheets("Last month").Cells(12 + j, 4) Then
            Exit For
        End If

        If j = n Then
            ThisWorkbook.Sheets("CVR").Cells(intCurRow2, 3) = CVR2(i)
            ThisWorkbook.Sheets("CVR").Cells(intCurRow2, 4) = Firm2(i)
            intCurRow2 = intCurRow2 + 1
        End If
    Next j
Next i

Columns("A:B").Select
ActiveSheet.Range("$A:$B").RemoveDuplicates Columns:=1, Header:=xlNo
Application.DisplayAlerts = False

Columns("C:D").Select
ActiveSheet.Range("$C:$D").RemoveDuplicates Columns:=1, Header:=xlNo
Application.DisplayAlerts = False

End Sub

insert/replace table by value range criteria in excel

$
0
0

I have 6 different tables(22 rows and 14 columns) with different discounts for multiple services who depends of purchases amount.

I need to make one worksheet, where cell containing value, who is entered by user, automatically changes whole discount table. For example i enter in A1 cell 15 and who table gets updated to Table2 discounts.

Table1 discounts get in efect if cell value 0-9;

Table2 discounts get in efect if cell value 10-20;

Table3 .......

Discount tables are already pre-made and i just need to change table by criteria who was entered. I think VLOOKUP could do a job here but im not sure about it, and on there hand that will require a lot of vlookup formula usage what will make reload much longer and eat more PC system. Maybe there is some other way how to swap all table by one action?

How to apply a font to a whole worksheet or all worksheets in excel using python?

$
0
0

How can I apply a font to a whole worksheet or all worksheets in an Excel (xls) document?

Is there a library available that I can use to do this? I haven't found any information on how to do this in xlrd, xlwt, or pandas.

Additionally, how can I do this to several .xls files at once?

How to copy a range to another worksheet with for each loop?

$
0
0

I would like to copy a range to an another worksheet and to insert before it 2 columns on the new worksheet. It doesn't copy the original range.

It works, if I copy to the same worksheet.

Set ws = ThisWorkbook.Sheets("Sh2")
Set ws2 = ThisWorkbook.Sheets("Sh3")
Set wb = ThisWorkbook

rowNum = ws.UsedRange.Rows.Count

For Each row In ws.Range("A1:A"& rowNum)
    ws2.Range("A1:A"& rowNum).Offset(0, 0).Value2 = wb.Name
    ws2.Range("A1:A"& rowNum).Offset(0, 1).Value2 = ws.Name
Next row

For Each cell In ws.UsedRange
    cell.Offset(10, 2).Value2 = cell.Value2
Next cell

I expect the column "A" contains the name of active workbook, the "B" the name of active worksheet, the other rows comes the original content. Now, the filename and worksheet's name copied to the new worksheet, but the content not.

Viewing all 89774 articles
Browse latest View live


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