excel-vba

VBA - Add sheets to variable and move to new workbook

眉间皱痕 提交于 2020-01-06 11:49:51
问题 I am trying to write a macro which can create up to 3 new worksheets, and at the end will move those sheets to a new workbook. Some, all or none of those sheets may be created, and I am struggling to move them all. I have tried adding their names to both a string and an array (with and without quotes to mimic if I manually typed the names of the sheets to move). This is what I have at the moment, but it is returning Run-Time error '9': Subscript out of range. If I only move one of the sheets

Excel VBA: Application defined or Object defined error

青春壹個敷衍的年華 提交于 2020-01-06 11:46:35
问题 I've written some code to look for sets of brackets in an excel file and white out the contents of the cells in between them. The code I have works for 26-27 lines before I get the error message. Here is the code: Sub macro() Dim white As Long Dim rowIndex As Long Dim colIndex As Long Dim lastRow As Long Dim lastCol As Long white = RGB(Red:=255, Green:=255, Blue:=255) With ActiveSheet lastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row lastCol = .Cells.Find("*",

VB - Rotate line about a point

若如初见. 提交于 2020-01-06 11:16:39
问题 I need to rotate an horizontal line about its end point in VB Excel. I tried various solution found on internet but they don't work well. I give you some images about what I want to do: This is my line: point A (72; 378) point B (165; 378) And I want to rotate the point A about the point B, the angle of rotation is variable. For example this is a 60 degrees rotation The letters A and B were added after the screenshot with a photo editor 回答1: Try this. Sub test() Dim x As Single, y As Single

VB - Rotate line about a point

痴心易碎 提交于 2020-01-06 11:15:44
问题 I need to rotate an horizontal line about its end point in VB Excel. I tried various solution found on internet but they don't work well. I give you some images about what I want to do: This is my line: point A (72; 378) point B (165; 378) And I want to rotate the point A about the point B, the angle of rotation is variable. For example this is a 60 degrees rotation The letters A and B were added after the screenshot with a photo editor 回答1: Try this. Sub test() Dim x As Single, y As Single

Getting a total copied set of rows in VBA and storing it in a variable

拥有回忆 提交于 2020-01-06 10:55:25
问题 I have a fairly simple syntax question: I'm trying to copy and paste n rows from one excel file to another. In addition, I'd like to store the total copied rows into a variable. Can someone help me accomplish this? For example: 1) Activate CSV file Apply Filter to Column B (Page Title) & uncheck "blanks" ("<>") filter** Windows("Test_Origin.xlsm").Activate ActiveSheet.Range("$A$1:$J$206").AutoFilter Field:=2, Criteria1:="<>" 2) Copy Filtered Lines with data (Excluding Row 1) Range("B2:F189")

Default value of Combobox(form control) VBA

余生长醉 提交于 2020-01-06 10:54:14
问题 Hey I have been searching a lot on the internet but I haven't been able to find the solution. I have atleast 10-15 combobox(form control) in my workbook. I want them to display a default value of say "Select type". Now, I have tried doing this using the ".listindex" but then it doesn't allow me to change the value in the combobox(as the default is set permanently). Can someone help? This is what I tried to use With ws(1).shapes("Chill1").controlformat .listindex = 1 End with 回答1: The default

I need some help on designing a program that will perform a minimization using VBA Excel

房东的猫 提交于 2020-01-06 10:51:55
问题 How do I use Excel VBA to find the minimum value of an equation? For example, if I have the equation y = 2x^2 + 14, and I want to make a loop that will slowly increase/decrease the value of x until it can find the smallest value possible for y, and then let me know what the corresponding value of x is, how would I go about doing that? Is there a method that would work for much more complicated equations? Thank you for your help! Edit: more details I'm trying to design a program that will find

Excel data validation: Change fill color without changing text

你离开我真会死。 提交于 2020-01-06 09:37:33
问题 I have a floor plan with about 50 resources that either need to be marked available, reserved, or occupied. I chose to use data validation in-cell drop-down list for each resource. Is it possible to keep the text in the data validation cell, use the source as the drop-down options, and change the fill color based on the selection? That might be hard to understand so I'll provide an example. Example given: A1:A3 is the source with Available, Reserved, and Occupied. Cell D3: Available, Reserved

Excel VBA / Refresh data from specific source without dialog

社会主义新天地 提交于 2020-01-06 09:08:07
问题 I have one sheet ("Sheet2") with imported data from TXT in my workbook. Data are refreshed every day from file ZLX02S_FG_ & "sufix". Name and path of the file are always known or calculated. File name = ZLX02S_FG_20180821_095910.txt Path name = C:\Users\lmisek\Desktop\WMS-L05-FG\ I have tried this code: Sub Refresh_Macro() With Worksheets("Sheet2").QueryTables(1) .Connection = "TEXT;C:\Users\lmisek\Desktop\WMS-L05-FG\ZLX02S_FG_20180821_095910.txt" .Refresh BackgroundQuery:=False End With End

Solving variable variable's names issue in excel

强颜欢笑 提交于 2020-01-06 08:39:30
问题 I have a programming issue concerning variable variable's names I need to make an questionaire in excel where answers to certain questions will either hide or unhide certain rows. I have no idea how to optimize it, although I searched for the solution for quite a while. Code sample which performs an action on one question Private Function RowNo(ByVal text1 As String) As Long Dim f As Range Set f = Columns(2).Find(text1, Lookat:=xlWhole) If Not f Is Nothing Then RowNo = f.Row Else RowNo = 0