worksheet

Excel VBA For Each Worksheet Loop

别来无恙 提交于 2019-11-26 20:36:13
问题 I am working on code to basically go through each sheet in my Workbook, and then update column widths. Below is the code I wrote; I don't receive any errors, but it also doesn't actually do anything. Any help is greatly appreciated! Option Explicit Dim ws As Worksheet, a As Range Sub forEachWs() For Each ws In ActiveWorkbook.Worksheets Call resizingColumns Next End Sub Sub resizingColumns() Range("A:A").ColumnWidth = 20.14 Range("B:B").ColumnWidth = 9.71 Range("C:C").ColumnWidth = 35.86 Range

Query my excel worksheet with VBA

天涯浪子 提交于 2019-11-26 17:15:58
问题 Is it possible to query a worksheet using VBA? I want to be able to select all the values in the time column i.e. (00:00) WHERE the day equals for example: Saturday I there any way to do this, a tutorial would be really helpful. Thanks 回答1: You can programmtically create an AutoFilter, then select the matching values: Dim ws As Worksheet: Set ws = ActiveSheet With ws .AutoFilterMode = False .Range("1:1").AutoFilter .Range("1:1").AutoFilter field:=2, Criteria1:="=Saturday", Operator:=xlAnd

How can I loop through a subset of worksheets?

纵饮孤独 提交于 2019-11-26 17:07:37
问题 I know how to loop through all the worksheets in a workbook, and how to exit once I reach an 'end-flag' worksheet: For Each ThisWorkSheet In Worksheets If ThisWorkSheet.Name = "FlagEnd" Then Exit For MsgBox "This worksheet name is: " & ThisWorkSheet.Name Next However I cannot get the loop to begin on a 'start-flag' worksheet (or even better on the worksheet right after the start-flag worksheet. For example the flagged start/end worksheets are in the middle of a bunch of other worksheets, so

VBA Worksheet change event bypass?

隐身守侯 提交于 2019-11-26 16:59:26
问题 I am fixing a spreadsheet. The programmer made a macro for each sheet to fire when the sheet is changed. This is good because it colour co-ordinates the sheet details when new information is added so I would like to keep this feature. I have written a macro which sorts the data and allows for removal and addition of new employees, this is in conflict with the change event macro and is causing my macro to have errors if they are both operational. Q. Is there a way to bypass the worksheet

Refer to sheet using codename

大城市里の小女人 提交于 2019-11-26 16:41:33
I get a "type mismatch" error in this code: With Worksheets(Sheet1) '* Error here 'my code here End With My sheet's CodeName is 'sheet1' . Can someone please help me remove the error? 1) Refer to sheet by Index: With Worksheets(1) '<stuff here> End With The `Index' is dependent on the "order of sheets in the workbook". If you shuffle your sheets order, this may not refer to the same sheet any more! 2) Refer to sheet by Name: With Worksheets("Your Sheet Name") '<stuff here> End With This is the .Name property of a worksheet, and is the name visible in the Excel worksheet tab and in brackets in

Copy worksheet from one workbook to another one using Openpyxl

跟風遠走 提交于 2019-11-26 14:46:49
问题 I have a large amount of EXCEL files (i.e. 200) I would like to copy one specific worksheet from one workbook to another one. I have done some investigations and I couldn't find a way of doing it with Openpyxl This is the code I have developed so far def copy_sheet_to_different_EXCEL(path_EXCEL_read,Sheet_name_to_copy,path_EXCEL_Save,Sheet_new_name): ''' Function used to copy one EXCEL sheet into another file. def path_EXCEL_read,Sheet_name_to_copy,path_EXCEL_Save,Sheet_new_name Input data: 1

xlsxwriter: is there a way to open an existing worksheet in my workbook?

冷暖自知 提交于 2019-11-26 13:47:10
问题 I'm able to open my pre-existing workbook, but I don't see any way to open pre-existing worksheets within that workbook. Is there any way to do this? 回答1: You cannot append to an existing xlsx file with xlsxwriter . There is a module called openpyxl which allows you to read and write to preexisting excel file, but I am sure that the method to do so involves reading from the excel file, storing all the information somehow (database or arrays), and then rewriting when you call workbook.close()

C# - How to add an Excel Worksheet programmatically - Office XP / 2003

元气小坏坏 提交于 2019-11-26 13:07:06
问题 I am just starting to fiddle with Excel via C# to be able to automate the creation, and addition to an Excel file. I can open the file and update its data and move through the existing worksheets. My problem is how can I add new sheets? I tried: Excel.Worksheet newWorksheet; newWorksheet = (Excel.Worksheet)excelApp.ThisWorkbook.Worksheets.Add( Type.Missing, Type.Missing, Type.Missing, Type.Missing); But I get below COM Exception and my googling has not given me any answer. Exception from

Excel tab sheet names vs. Visual Basic sheet names

随声附和 提交于 2019-11-26 09:14:14
问题 It seems that Visual Basic can not reference sheets according to user-modified sheet names. The worksheet tabs can have their names changed, but it seems that Visual Basic still thinks of the worksheet names as Sheet1, etc., despite the workbook tab having been changed to something useful. I have this: TABname = rng.Worksheet.Name \' Excel sheet TAB name, not VSB Sheetx name. but I would like to use sheet names in Visual Basic routines. The best I could come up so far is to Select Case the

How to add a named sheet at the end of all Excel sheets?

删除回忆录丶 提交于 2019-11-26 04:21:31
问题 I am trying to add an Excel sheet named \"Temp\" at the end of all existing sheets, but this code is not working: Private Sub CreateSheet() Dim ws As Worksheet ws.Name = \"Tempo\" Set ws = Sheets.Add(After:=Sheets(Sheets.Count)) End Sub Can you please let me know why? 回答1: Try this: Private Sub CreateSheet() Dim ws As Worksheet Set ws = ThisWorkbook.Sheets.Add(After:= _ ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)) ws.Name = "Tempo" End Sub Or use a With clause to avoid repeatedly calling