excel-2007

Get data from multiple sheets in a selected workbook

本秂侑毒 提交于 2019-12-17 16:35:10
问题 I'm new to macros in Excel and I need to make a macro that get data from multiple sheets in a selected workbook. So far I have this code to select a file and get data from sheet 1, but I want it to be able to get information from all the sheets in the selected file. Sub MergeSelectedWorkbooks() Dim SummarySheet As Worksheet Dim FolderPath As String Dim SelectedFiles() As Variant Dim NRow As Long Dim FileName As String Dim NFile As Long Dim WorkBk As Workbook Dim SourceRange As Range Dim

Delete all data rows from an Excel table (apart from the first)

无人久伴 提交于 2019-12-17 15:57:13
问题 Just recently I've been trying to delete all data rows in a table, apart from the first (which needs to just be cleared) Some of the tables being actioned could already have no rows, so I was running it to problems as using .DataBodyRange.Rows.Count on a table with no rows (just header and/or footer) causes errors. I looked all over for a solution an could not find a whole one, so I hope my answer to this question will be useful to others in the future. 回答1: Your code can be narrowed down to

Cannot VBA write data to cells in Excel 2007/2010 within a function

余生长醉 提交于 2019-12-17 07:39:35
问题 I want to set value for cells by VBA. I have googled, and see some resolution: Sheets("SheetName").Range("A1").value = someValue Sheets("SheetName").Cells(1,1).value = someValue With this kind of code, I can just read data from cell A1 but I cannot set a new value to it. Update The code to set cell A1 value is put within a Function as below. Function abb() Sheets("SheetName").Range("A1").value = 122333 abb = 'any thing' End Function In cell B2, I set =abb() and hit enter. I get #VALUE but

Cannot VBA write data to cells in Excel 2007/2010 within a function

时间秒杀一切 提交于 2019-12-17 07:39:20
问题 I want to set value for cells by VBA. I have googled, and see some resolution: Sheets("SheetName").Range("A1").value = someValue Sheets("SheetName").Cells(1,1).value = someValue With this kind of code, I can just read data from cell A1 but I cannot set a new value to it. Update The code to set cell A1 value is put within a Function as below. Function abb() Sheets("SheetName").Range("A1").value = 122333 abb = 'any thing' End Function In cell B2, I set =abb() and hit enter. I get #VALUE but

filter out multiple criteria using excel vba

雨燕双飞 提交于 2019-12-17 02:31:55
问题 I have 8 variables in column A, 1,2,3,4,5 and A, B, C. My aim is to filter out A, B, C and display only 1-5. I can do this using the following code: My_Range.AutoFilter Field:=1, Criteria1:=Array("1", "2", "3","4","5"), _ Operator:=xlFilterValues But what the code does is it filters variables 1 to 5 and displays them. I want to do the opposite, but yielding the same result, by filtering out A, B, C and showing variables 1 to 5 I tried this code: My_Range.AutoFilter Field:=1, Criteria1:=Array(

“SaveAS” macro in excel with password protection

被刻印的时光 ゝ 提交于 2019-12-16 18:02:59
问题 Hi I have this macro in excel file: ActiveWorkbook.SaveAs filename:="C:\SAP Imports\Sales Orders\" & Range("A1") & ".xlsm", FileFormat:= _ xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _ , CreateBackup:=False This macro is password protected. Whenevr I run this I get "run time" error and I am not able to figure out whats wrong with my code. Should I write my password instead of writing "". Please advise. 回答1: If the directory does not exist, the macro will fail.

Cut Paste data from excel sheet using Autofilter in Excel VBA

此生再无相见时 提交于 2019-12-14 04:08:47
问题 Current i have an excel with roughly 200000+ records and i need to filter data based on a column. The column has around 5 values and i need to filter out 2 values in one sheet and the rest 3 to remain in the same sheet. Now instead of using cell by cell comparison to check whether the value of the cell falls in any of the above 2 values and then cut paste the row into another sheet. This wouldn't work with 200k+ records and simply hangs,. Instead am planning to take the auto filter method. I

How to disable (or remove) the “protect sheet” and “protect workbook” button in excel 2007 menu?

北城余情 提交于 2019-12-14 03:56:37
问题 I'm using VBA and I would like to disable the "protect sheet" and "protect workbook" button in excel 2007 menu. How can I do that ? Thanks in advance for any help. Best regards 回答1: You cannot affect the ribbon using VBA without the "customUI xml mechanism". See Excel 2007: Ribbon customization - Disable custom buttons. To learn more about RibbonX, you can read this MSDN article: Using RibbonX from Visual Basic. 来源: https://stackoverflow.com/questions/4689019/how-to-disable-or-remove-the

Using VBA to select a dynamic range of cells and create a chart

こ雲淡風輕ζ 提交于 2019-12-14 03:55:13
问题 I am attempting to use VBA to create a chart using dynamic ranges. Specifically, I have an Excel table as follows Based on this data, I would like to create a chart, with the date ranges changed as per requirement. For example, at one instance, I would be required to produce a chart for 1st July - 6th July, and at another, from 10th July - 14th July. The following is my attempt at generating such a chart, but I feel there would be much better ways other than mine. Hence, my question, is there

How to check that excel cell value has spaces… excel 2007

人盡茶涼 提交于 2019-12-14 02:17:46
问题 I have an Excel file that contains some values. I need to check if a cell value contains spaces. For example, sometimes a user will write some values in the cell but mistakenly press Enter or Space in the cell. I want to see if the cell value has spaces inside... Please tell me how to do this. Thanks 回答1: Let's say I type "ABC " in cell A1 (ABC followed by a space). Either of these formulas should help: =LEN(A1)=LEN(TRIM(A1)) =EXACT(A1,TRIM(A1)) For a VBA version: Function HasSpaces(rng As