excel-vba

Checking if a value is a member of a list

依然范特西╮ 提交于 2020-01-01 08:33:05
问题 I have to check a piece of user input against a list of items; if the input is in the list of items, then direct the flow one way. If not, direct the flow to another. This list is NOT visible on the worksheet itself; it has to be obfuscated under code. I have thought of two strategies to do this: Declare as an enum and check if input is part of this enum , although I'm not sure on the syntax for this - do I need to initialise the enum every time I want to use it? Declare as an array and check

Perform a find on hidden cells

 ̄綄美尐妖づ 提交于 2020-01-01 08:27:51
问题 I have a computed range of values in a hidden column which I use for a dropdown box. To figure out which value the user has selected, I try to run a Find on that range, but for some reason Excel won't return the cell corresponding with their selection so long as the column is hidden. How can I get Find working on cells in the hidden range. Remember - I'm searching cell calculated values, not formulas. The following does not work: Set inserted = Range("RDS_Event_IDs").Find(Range("SelectedEvent

Excel (2007) VBA - .Formula with quotes in it

孤街浪徒 提交于 2020-01-01 08:25:10
问题 I tried putting the following code into a program yesterday. VBA called an error. I assume it is because of the double quotes inside the formula. I googled and all results I found just gave the basic of putting formulas in, but none explained how to get around quotes inside. (there was a With statement before this, Pivot is a worksheet name) .Range("A2").Formula = "=IF(Pivot!A5="",A1,Pivot!A5)" Any help is much appreciated. Thanks! 回答1: Whenever in doubt, record a macro if it allows :) Try

Disable all dialog boxes in Excel while running VB script?

最后都变了- 提交于 2020-01-01 07:57:08
问题 I have some code in VB that saves all XLSM files as XLSX. I already have the code that will do that for me, but dialog boxes show up for every action. This was fine for a few dozen files. However, I'm going to use this on hundreds of XLSM files at once, and I can't just sit at my computer all day clicking dialog boxes over and over. The code I've tried is pretty much: Application.DisplayAlerts = False While this doesn't cause an error, it also doesn't work. The boxes give a warning about

VBA - Execute string as command in Excel

做~自己de王妃 提交于 2020-01-01 07:23:12
问题 In the last 30 minutes I am trying to execute a string in VBA as a command. The command is like this and it runs ok: activesheet.chb_g_ba1.visible = true What I am trying to do is to set "chb_g_ba1" as a variable, because there are "chb_g_ba2", "chb_g_ba3", etc as well. What I have tried so far - things like: dim l_counter as long: l_counter = 1 Evaluate (CStr("me.chb_g_ba" & l_counter & ".visible = true")) Or even Eval Eval (CStr("me.chb_g_ba" & l_counter & ".visible = true")) Eval is a

Object variable or with block not set -

旧时模样 提交于 2020-01-01 05:28:12
问题 So, I have a worksheet, in which I want to search for a value of Range("M" & i) in Range("A:A"). However, when I try to run this code, it returns an error: "Run-Time Error '91': Object Variable or With block not set. When I click debug, it finds an error on SearchIn = Range("A:A") I did google the internet and this site (found something), but I still can't solve the issue. Anyone got a clue? Sub Find_Replace() Dim i As Integer Dim SearchIn As Range Dim SearchedObject As Range Dim FinalCell As

Margins in Visual Basic Editor Excel 2016

醉酒当歌 提交于 2020-01-01 04:50:08
问题 My visual basic editor only allows me to type in one column. In other words, only one letter per line. Please see the image below. How do I fix this? (visual basic for mac) 回答1: This is a bug in Excel. To fix this, you simply need to update Excel. Click "Help" > "Check for Updates", then close Excel. Next, click the "Check for Updates" button in the Microsoft AutoUpdate window, and select for Excel to update. After updating, when you reopen Excel the problem will be fixed. 回答2: Never mind,

Is the poor performance of Excel VBA auto-instancing a myth?

谁说我不能喝 提交于 2020-01-01 04:35:06
问题 The accepted wisdom is that using a construct like Dim dict As New Dictionary is poorer in performance than Dim dict As Dictionary / Set dict = New Dictionary . The explanation is that the former example - auto-instantiation - defers instantiation until the first usage of the variable dict . And thus, every time dict is referenced, the compiled code must first check whether dict is equal to Nothing. But it occurs to me that compiled code does this anyway. You will get an error any time you

Running R from Excel VBA without RExcel

半腔热情 提交于 2020-01-01 03:42:14
问题 Can this process be simplified? First, I manually open this file in R: C:\R\ExampleModel\ModelScript.R From R-Editor, when the code below is run from the open ModelScript.R file, it processes the Model.R script correctly. source("C:\\R\\ExampleModel\\Model.R", echo=T) Within Excel, I want to run the source code above without manually opening ModelScript.R from R first. Is there anything I can modify in the VBA code below to process the source() command automatically from Excel/VBA? If a batch

Active cell as input to formula

佐手、 提交于 2020-01-01 03:24:32
问题 I was wondering if I can use the active cell, by that I mean the cell that is "highlighted" at a given time with the square border after there was a mouse click there, as an argument in a function. For example, I have created a table with weighted averages with 3 weights: w1 is given in the column headers (kindly see the file below), w2 in the row headers, and w3 which complements w1 and w2 to 1. What I'd like to do is have cells outside the table show the weights the average got when a cell