All Questions

341
votes
11answers
163759 views

How to avoid using Select in Excel VBA

I've heard much about the understandable abhorrence of using .Select in Excel VBA, but am unsure of how to avoid using it. I am finding that my code would be more re-usable if I were able to use varia...
122
votes
10answers
74702 views

Error in finding last used cell in VBA

When I want to find the last used cell value, I use: Dim last_row As Integer Dim LastRow As Long LastRow = Range("E4:E48").End(xlDown).Row Debug.Print LastRow I am getting the wrong output when ...
643
votes
36answers
257422 views

How do I properly clean up Excel interop objects?

I'm using the Excel interop in C# (ApplicationClass) and have placed the following code in my finally clause: while (System.Runtime.InteropServices.Marshal.ReleaseComObject(excelSheet) != 0) { } exce...
1428
votes
40answers
856205 views

Create Excel (.XLS and .XLSX) file from C#

How can I create an Excel Spreadsheet with C# without requiring Excel to be installed on the machine that's running the code?
22
votes
2answers
51502 views

Convert matrix to 3-column table ('reverse pivot', 'unpivot', 'flatten', 'normalize')

I need to convert the Excel matrix FIRST in the table LATER: FIRST: P1 P2 P3 P4 F1 X F2 X X F3 X X F4 X X LATER: F P VALUE...
233
votes
32answers
399058 views

Reading Excel files from C#

Is there a free or open source library to read Excel files (.xls) directly from a C# program? It does not need to be too fancy, just to select a worksheet and read the data as strings. So far, I've ...
161
votes
5answers
433886 views

Loop through files in a folder using VBA?

I would like to loop through the files of a directory using vba in Excel 2010. In the loop, I will need the filename, and the date at which the file was formatted. I have coded the following wh...
26
votes
2answers
28698 views

MS Excel crashes when vba code runs

I am having a problem with excel crashing when i run VBA code on an excel sheet. I have some code to add a formula to a range of cells as follows: Private Sub Worksheet_Change(ByVal Target As Range) ...
11
votes
3answers
19919 views

How to copy a line in excel using a specific word and pasting to another excel sheet?

I have checked a bunch of different posts and can't seem to find the exact code I am looking for. Also I have never used VBA before so I'm trying to take codes from other posts and input my info for i...
20
votes
3answers
54275 views

Excel VBA, getting range from an inactive sheet

This script works fine when I'm viewing the "Temp" sheet. But when I'm in another sheet then the copy command fails.. It gives a "Application-defined or object-defined error" Sheets("Temp").Range(Cel...

Previous Next