excel-vba

Excel: Run A Macro On Cell Click

大憨熊 提交于 2020-03-24 03:18:18
问题 I am using the following code to insert todays date into a cell when a user clicks onto another cell in that row. At the moment the code is set out like so; if a user clicks cell AQ8 then insert date into cell AS8. Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) If Target.Address = "$AQ$8" Then Range("AS8").Value = DATE End If End Sub however, now i want to change this code slightly so that when a user changes any AQ cell in either row then the subsequent AS cell has the

Incorrect result from CurrentRegion when used in a function called from a cell

我的梦境 提交于 2020-03-23 12:23:31
问题 I'm trying to write a VBA function to be called from a cell. In this function I need to use the CurrentRegion property but it returns an unexpected result. The function: Function GetVarRange() As String Dim rngRangeToLeft As Range, wks As Worksheet Set wks = Application.Caller.Worksheet Set rngRangeToLeft = wks.Range("A1").CurrentRegion GetVarRange = rngRangeToLeft.Address End Function The result I get in the cell is $A$1. There are values in A1, and all around it, the CurrentRegion is

Detect blank Excel cell using interop.excel in C#

别等时光非礼了梦想. 提交于 2020-03-23 06:25:07
问题 I'm trying to parse text from an Excel doc in C#. The problem is that I can't find a way to detect (and ignore) blank cells. I've searched this forum and many others but I can still not get it to work. I'm using Microsoft.Office.Interop.Excel in Visual Studio 2010 C#. I have no problem with opening Excel and reading and storing data in it. Its just that I can't skip blank cells so my program will consequentially store blank values. I have defined my woorksheet the following way: Excel

ADO: Excel: Is it possible to open recordset on table name?

a 夏天 提交于 2020-03-21 06:22:51
问题 I have looked on the web but did not find any answer. So i am putting it here. Code snippet: ( where case 1 is not working.. ) _bstr_t strCnn(L"Provider='Microsoft.ACE.OLEDB.12.0';DataSource=C:\\Book.xlsx;Extended Properties=\"Excel 12.0 Xml; HDR = YES\""); hr = pConn->Open(strCnn, "", "", adConnectUnspecified); // success **LPCSTR strQuery = "select * FROM Table1"; // case1: Not working** LPCSTR strQuery = "select * FROM [Sheet1$]"; // case2: working LPCSTR strQuery = "select * FROM [Sheet1

Array formula to VBA

一个人想着一个人 提交于 2020-03-19 05:02:00
问题 I have an Excel spreadsheet with two worksheets titled “Cities” and “Data”. The "Data" page contains 108264 rows of data, and columns progress all the way up to column AT. Under the Cities worksheet, I have a list of 210 cities from rows B4 to B214. Next to it (Column C) is a list of the counts of codes used for each city (i.e. how many codes did that city use). The next 20 columns (Columns D to W) should show a sequence of the most commonly used codes for each city (i.e. most common to least

Array formula to VBA

让人想犯罪 __ 提交于 2020-03-19 04:58:37
问题 I have an Excel spreadsheet with two worksheets titled “Cities” and “Data”. The "Data" page contains 108264 rows of data, and columns progress all the way up to column AT. Under the Cities worksheet, I have a list of 210 cities from rows B4 to B214. Next to it (Column C) is a list of the counts of codes used for each city (i.e. how many codes did that city use). The next 20 columns (Columns D to W) should show a sequence of the most commonly used codes for each city (i.e. most common to least

VBA for Excel throws “Object variable or with block variable not set” when there is no Object

落爺英雄遲暮 提交于 2020-03-17 10:35:51
问题 In my code, I have declared these variables: Dim Field_Name, Datatype, row As Integer Then, inside a For loop, I have this code: Field_Name = Worksheets(i).UsedRange.Find("Field Name").Column Datatype = Worksheets(i).UsedRange.Find("Datatype").Column row = Worksheets(i).UsedRange.Find("Field Name").row + 1 However, that code throws the "Object variable or with block variable not set" run-time error. According to the API, the Range.Column and Range.row property is a read-only Long. I have

VBA for Excel throws “Object variable or with block variable not set” when there is no Object

无人久伴 提交于 2020-03-17 10:35:24
问题 In my code, I have declared these variables: Dim Field_Name, Datatype, row As Integer Then, inside a For loop, I have this code: Field_Name = Worksheets(i).UsedRange.Find("Field Name").Column Datatype = Worksheets(i).UsedRange.Find("Datatype").Column row = Worksheets(i).UsedRange.Find("Field Name").row + 1 However, that code throws the "Object variable or with block variable not set" run-time error. According to the API, the Range.Column and Range.row property is a read-only Long. I have

How to import long number from csv to excel without converting to scientific notation in VBA

若如初见. 提交于 2020-03-17 07:08:33
问题 I opened semicolon delimited txt file with this code below and long account number showed up as scientific notation after saving to excel regardless of formatting to text that column. What did I do wrong here? Application.ScreenUpdating = False Workbooks.OpenText fileName:=Filetxt, Origin:=xlWindows, StartRow _ :=2, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _ ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=True, Comma:=False, _ Space:=False, Other:=False, Local:=True, _

How to import long number from csv to excel without converting to scientific notation in VBA

孤街醉人 提交于 2020-03-17 07:08:05
问题 I opened semicolon delimited txt file with this code below and long account number showed up as scientific notation after saving to excel regardless of formatting to text that column. What did I do wrong here? Application.ScreenUpdating = False Workbooks.OpenText fileName:=Filetxt, Origin:=xlWindows, StartRow _ :=2, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _ ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=True, Comma:=False, _ Space:=False, Other:=False, Local:=True, _