excel-vba

VBA format cells to General

醉酒当歌 提交于 2020-01-03 08:48:43
问题 I would like to format a excel file to "General", but it's not working for all cells (some are custom, pourcentage...). here is my code : With ActiveSheet.Range("A1").Resize(LineIndex, 1) .Value = WorksheetFunction.Transpose(strLine) .NumberFormat = "General" 'DEFINE THE OPERATION FULLY!!!! .TextToColumns Destination:=.Cells(1), DataType:=xlDelimited, _ TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, _ Tab:=False, Semicolon:=False, Comma:=False, Space:=False, _ Other:=True,

VBA Excel “Compile error: Object Required”

可紊 提交于 2020-01-03 08:08:30
问题 I am working on VBA code in excel and i have the following piece of code Set strModel = Right(rng.Offset(0, 13).Value, Len(rng.Offset(0, 13).Value) - 4) When I run the code I get a compile error to debug and it reads Object Required . What is it asking me to do? This is a larger piece of the code: strHSLtemp = "C:\Users\Desktop\To Do\MidDay Orders Macro Tool\Temp Files\HSL Orders Temp.xlsx" wbHSLtemp = Dir(strHSLtemp) Set wbHSLtemp = Workbooks.Open(strHSLtemp) Set wsHSLtemp = wbHSLtemp.Sheets

VBA Excel “Compile error: Object Required”

大城市里の小女人 提交于 2020-01-03 08:08:21
问题 I am working on VBA code in excel and i have the following piece of code Set strModel = Right(rng.Offset(0, 13).Value, Len(rng.Offset(0, 13).Value) - 4) When I run the code I get a compile error to debug and it reads Object Required . What is it asking me to do? This is a larger piece of the code: strHSLtemp = "C:\Users\Desktop\To Do\MidDay Orders Macro Tool\Temp Files\HSL Orders Temp.xlsx" wbHSLtemp = Dir(strHSLtemp) Set wbHSLtemp = Workbooks.Open(strHSLtemp) Set wsHSLtemp = wbHSLtemp.Sheets

Nested With Statement hierarchy

让人想犯罪 __ 提交于 2020-01-03 08:07:08
问题 I've come across this a couple of times recently and was just curious if there was an easier way to do this... With Activeworkbook 'Do Stuff With .Sheets(1) 'More stuff Done '... 'But now I need to refer to or pass the Sheet in the last With Statement SomeFunctionAnswer = SomeFunction Activeworkbook.Sheets(1) End With 'Yet more stuff Done End With Does it have to be fully written out, or is there some way of notating it that makes it easier/cleaner? Perhaps there is some sort of property or

What is the difference between .Value = “” and .ClearContents?

懵懂的女人 提交于 2020-01-03 07:40:33
问题 If I run the following code Sub Test_1() Cells(1, 1).ClearContents Cells(2, 1).Value = "" End Sub When I check Cells(1, 1) and Cells(2, 1) using formula ISBLANK() both results return TRUE . So I'm wondering: What is the difference between Cells( , ).Value = "" and Cells( , ).ClearContents ? Are they essentially the same? If I then run the following code to test the time difference between the methods: Sub Test_2() Dim i As Long, j As Long Application.ScreenUpdating = False For j = 1 To 10 T0

How do I format Time in [h]:mm excel format using format() function in VBA

笑着哭i 提交于 2020-01-03 07:28:14
问题 Is it possible to format time in [h]:mm format using VBA? [h]:mm format in excel would show 25 hours as 25:00, 125 hours as 125:00 I've tried several things such as: format(datetime, "[h]:mm") format(datetime, "H:mm") format(datetime, "hh:mm") None of these have the desired effect. I've also had a look through the MS help and can't find anything useful. 回答1: Use the TEXT worksheet function via the application object, as so: x = Application.Text(.294,"[h]:mm") 回答2: JFC beat me to it, but here

CPLEX OPL and Excel VBA Integration

为君一笑 提交于 2020-01-03 06:59:31
问题 I have to run the same optimization model many times with different parameters for research purposes. (I am trying to observe the results I'll get off a single model when I increase a parameter) The easiest way for me to do is to use Excel Macros as it would take me forever to solve each model one by one and record the results. However I have no idea how I will make VBA call the CPLEX Solver and read all my parameters from my excel sheet and write the results back there. If I am to put what I

How do I get a subset of elements in an array in excel vba?

╄→гoц情女王★ 提交于 2020-01-03 06:41:12
问题 How do I get the 3rd through 6th elements in an array in excel vba? Something like the following. Dim x(9) as variant, y(3) as variant y(0:3) = x(2:5) 回答1: In VBA, unlike in python for example, we cannot directly "subset" an array. We can only loop for the indices of interest by specifying i and j to be between certain bounds e.g. i to be between rows 1 and 2, j to be between columns 2 and 3. Of course, we can also directly index into the array by position e.g. arr(1) . i just a variable

Running out of VBA Memory

不问归期 提交于 2020-01-03 06:35:44
问题 Im running the code below, which does exactly what I want it to. The issue I am having with it though is that when I keep the sheet running for a period of time like 10 min I get a pop up error message saying I have run out of memory. Is there something I could put in my code that I could use to prevent this? My code is as below, Sub auto_open() Call ScheduleCopyPriceOver End Sub Sub ScheduleCopyPriceOver() TimeToRun = Now + TimeValue("00:00:10") Application.OnTime TimeToRun, "CopyPriceOver"

MinimizeOutlookWindow not works

我与影子孤独终老i 提交于 2020-01-03 06:14:04
问题 I have calling 3 procedures respectively: Sub SendMail() OutlookSendMail strTo:="DesEMailAddress", _ strSubject:="BackUp DB", _ strBody:=ThisWorkbook.name & vbCr, _ strAttach:=sFile OpenOutlook MinimizeOutlookWindow End Sub Unfortunately the third one ( MinimizeOutlookWindow ) seems a comment in this order! (not working) Else if I do run that absolutely in another subroutine when Outlook window is opened, it minimizing the window truly. How can solve this as MinimizeOutlookWindow procedure do