excel-vba

Create Table in Excel Worksheet using VBA

流过昼夜 提交于 2020-01-22 15:15:01
问题 I have this code below that will auto select a range. Does anyone know how I can add code to create a table to the selected range? Thanks! Sub DynamicRange() 'Best used when first column has value on last row and first row has a value in the last column Dim sht As Worksheet Dim LastRow As Long Dim LastColumn As Long Dim StartCell As Range Set sht = Worksheets("Sheet1") Set StartCell = Range("D9") 'Find Last Row and Column LastRow = sht.Cells(sht.Rows.Count, StartCell.Column).End(xlUp).Row

Bolding a specific part of cell

谁都会走 提交于 2020-01-22 13:54:11
问题 I have a cell that is referenced as ="Dealer: " & CustomerName . CustomerName is a dictionary referenced name. How could I go along of bolding only "Dealer:" and not the Customer name. Example: Dealer: Josh I have tried Cells(5, 1).Characters(1, 7).Font.Bold = True But it only seems to work on non referenced cells only. How could I get this to work on a referenced cell? 回答1: You can use the below function to bold some input text within a formula So in your cell you can now type =Bold("Dealer:

Amount of rows in sheet

亡梦爱人 提交于 2020-01-22 13:38:02
问题 Goal: A variable should contain amount of rows from a specific sheet. Problem: What syntax code in Excel VBA do I need to count amount of rows from sheet? 回答1: Using the usedrange method is one of my favourites but it needs to be treated with care. It has a few flaws/gotchas. It is a known problem that excel does not keep track of the used range very well. Any reference to the used range via VBA will reset the value to the current used range. So try running this sub procedure when you are

Amount of rows in sheet

烈酒焚心 提交于 2020-01-22 13:37:09
问题 Goal: A variable should contain amount of rows from a specific sheet. Problem: What syntax code in Excel VBA do I need to count amount of rows from sheet? 回答1: Using the usedrange method is one of my favourites but it needs to be treated with care. It has a few flaws/gotchas. It is a known problem that excel does not keep track of the used range very well. Any reference to the used range via VBA will reset the value to the current used range. So try running this sub procedure when you are

VBA How to copy the content of a cell without .Select

只谈情不闲聊 提交于 2020-01-22 11:42:08
问题 I am writing a method that can take the Target and paste the cell exactly to another cell. The cell is a shipping label with some fancy formating. Is there a way I can do it? Originally I have this: Worksheets("Label").Range("A1").Value = Worksheets("Get Address").Range("A28").Value It worked for the plain text. However I lost the styling I created, they are different because after the first line, the style is different: I also tried to use Macro Recorder and I got a solution using .Select ,

Move a dynamic created control on a form using VBA

馋奶兔 提交于 2020-01-21 23:42:36
问题 In Excel I have created a form. On this form I have created 3 buttons. I want to be able to move these button at runtime. The problem which I have is how do I reference the buttons at runtime? 回答1: Private Sub CommandButton1_Click() Me.Controls("CommandButton1").Move 0, 0 End Sub 回答2: The problem which I have is how do I reference the buttons at runtime? It depends on how are you assigning the names to the button. Here is a simple way to create a command button at runtime and move it using

Excel VBA - Apply auto filter and Sort by specific colour

限于喜欢 提交于 2020-01-21 19:01:27
问题 I have an auto-filtered range of data. The auto filter was created by the following VB code: Sub Colour_filter() Range("A4").Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False Selection.AutoFilter End Sub I would like to sort the values in column "A" (the data actually start from cell "A4") by the following colour ( Color = RGB

Excel VBA - Apply auto filter and Sort by specific colour

ぐ巨炮叔叔 提交于 2020-01-21 19:01:07
问题 I have an auto-filtered range of data. The auto filter was created by the following VB code: Sub Colour_filter() Range("A4").Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False Selection.AutoFilter End Sub I would like to sort the values in column "A" (the data actually start from cell "A4") by the following colour ( Color = RGB

Excel VBA - Apply auto filter and Sort by specific colour

微笑、不失礼 提交于 2020-01-21 19:00:06
问题 I have an auto-filtered range of data. The auto filter was created by the following VB code: Sub Colour_filter() Range("A4").Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False Selection.AutoFilter End Sub I would like to sort the values in column "A" (the data actually start from cell "A4") by the following colour ( Color = RGB

Expected End of Statement

大憨熊 提交于 2020-01-21 18:18:23
问题 Ok, I have used a formula that was suggested that works well, should work without an issue but now I am getting this error: Expected End of Statement Here is the formula Range("B4").FormulaR1C1 = "=IF(RC[-1]="T",VLOOKUP(RC[7],treatlookup,11,FALSE),VLOOKUP(RC[7],itemlookup,22,FALSE))" Not sure what is going on, why it is happening. Any suggestions. Thanks, 回答1: Escape the embedded double-quotes ( "T" ) by doubling them ( ""T"" ): Range("B4").FormulaR1C1 = "=IF(RC[-1]=""T"",VLOOKUP(RC[7]