excel-vba

Sort a Range before pasting Excel VBA

落爺英雄遲暮 提交于 2020-01-05 06:54:30
问题 I'm using the following code to copy a particular range from a Workbook to another Workbook , its working fine. But now i need to sort the Range in ascending order just before pasting to the destination sheet without changing the source. Please help. With Workbooks(strExcelFile).Sheets(strSheetName) .Range(strRange).Copy End With ActiveSheet.Range(strDestCell).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False 回答1: Take advantage of the fact that once you

Excel VBA function: How to pass range, convert to array, reverse, and return array

主宰稳场 提交于 2020-01-05 06:52:08
问题 I am trying to do some array math in Excel which requires me to reverse a number of 1-dimensional ranges a good amount of times, so I want to write a function for it, rather than create reverses in the spreadsheet. I have written a reverse() function in VBA but it returns #VALUE! errors in the spreadsheet. This happens no matter array size, nor whether inputting a same size array function or enclosing with a summary function like SUM(). I verified that the reversing logic works as a Sub. This

Excel VBA Array Loop Troubleshooting: Using Redim and UBound, 1- and 2-dimensional arrays

浪尽此生 提交于 2020-01-05 05:59:41
问题 I came here from Stackover Topic to doing faster macro. I got answer but this code not working and i am asking to you, (i tried to fix) Sub Faster_Method() Dim objIE As InternetExplorer Dim Prc1 As String Set objIE = New InternetExplorer Dim Search_Terms() As Variant Dim CopiedData() As Variant objIE.Visible = True Search_Terms() = ActiveSheet.Range("A1:A121").Value ReDim CopiedData(1 To UBound(Search_Terms) + 1) For a = 1 To UBound(Search_Terms) + 1 objIE.navigate "https://opskins.com/?loc

Clear cell content based on another cell calculation

狂风中的少年 提交于 2020-01-05 05:56:16
问题 this is an Excel/VBA question: I have a cell A1 in sheet2 linked cell A1 in sheet1 (simply A1='sheet1'!A1 ). A1 in sheet1 is a data validation drop down menu. I want to clear the content of A2 in sheet2 every time the content of A1 in sheet2 changes/is updated. That is every time the value of A1 in sheet1 is changed using the drop down menu. I tried using a Worksheet_Change event macro ( which I do not fully understand ) but it won't work with a cell that updates from a calculation. It also

Clear cell content based on another cell calculation

人走茶凉 提交于 2020-01-05 05:56:12
问题 this is an Excel/VBA question: I have a cell A1 in sheet2 linked cell A1 in sheet1 (simply A1='sheet1'!A1 ). A1 in sheet1 is a data validation drop down menu. I want to clear the content of A2 in sheet2 every time the content of A1 in sheet2 changes/is updated. That is every time the value of A1 in sheet1 is changed using the drop down menu. I tried using a Worksheet_Change event macro ( which I do not fully understand ) but it won't work with a cell that updates from a calculation. It also

multipoint regular expressions match with less for loops and less class re-initialization. optimization

一世执手 提交于 2020-01-05 05:56:07
问题 Is there a way to do multiple regular expressions matches in vba without instantiating multiple instances of the regexp object? For example I want to do several points of regular expression matching between several different fields of data. For illustrative purposes consider this. column 1 column 2 column 3 AAATDD Airplane Transportation/Airplane BBBTDD Bus Transportation/Bus CCCFDD Chocolate Food/Chocolate DDDFDD Dog Food/Potato So as you can see the first letter in Column 1 is A, which

multipoint regular expressions match with less for loops and less class re-initialization. optimization

霸气de小男生 提交于 2020-01-05 05:56:05
问题 Is there a way to do multiple regular expressions matches in vba without instantiating multiple instances of the regexp object? For example I want to do several points of regular expression matching between several different fields of data. For illustrative purposes consider this. column 1 column 2 column 3 AAATDD Airplane Transportation/Airplane BBBTDD Bus Transportation/Bus CCCFDD Chocolate Food/Chocolate DDDFDD Dog Food/Potato So as you can see the first letter in Column 1 is A, which

Reading first few characters in large text files in VBA

浪尽此生 提交于 2020-01-05 05:47:10
问题 I'm trying to read the first few characters in large (>15MB) files in excel. Right now, I'm using the typical: Set MyObject = New Scripting.FileSystemObject Set mySource = MyObject.GetFolder(mySourcePath) For Each myFile In mySource.Files With New Scripting.FileSystemObject With .OpenTextFile(myFile, ForReading) test_str = .ReadLine 'Do things End With End With Next The issue is with large files, I (believe) you're loading into memory the WHOLE thing only to read the first few characters. Is

Sort combobox values alphabetically

喜欢而已 提交于 2020-01-05 05:42:08
问题 I have a combobox in a userform for excel. What is the easiest way to sort it alphabetically? The values for it are hardcoded in vba and new ones are just added to the bottom so they are not in any kind of order already. The userform is currently being used so that our users can import data from our database into excel. The combobox is there so they can specify which client data to import. 回答1: As you are adding them, compare them to the values already in the combobox. If they are less than

Excel VBA Checking if Addin Is Installed But Not Open

隐身守侯 提交于 2020-01-05 05:40:28
问题 I have the following code to check if a required addin is installed/available before calling scripts within that Addin from the current context: Function IsAddinEnabled(addinName as string) As Boolean IsAddinEnabled = True Dim myAddin As addin On Error GoTo NotExists Set myAddin = Application.AddIns2(addinName) If myAddin.IsOpen = False Then ' this logic is my workaround myAddin.Installed = False 'uninstall myAddin.Installed = True ' install to "Open" the addin Else myAddin.Installed = True