Rifat Hassan, BSc, Electrical and Electronic Engineering, Bangladesh University of Engineering and Technology, has worked with the ExcelDemy project for almost 2 years. Within these 2 years, he has written over 250 articles. He has also conducted a few Boot Camp sessions on effective coding, especially Visual Basic for Applications (VBA). Currently, he is working as a Software Developer to develop and deploy additional add-ins to enhance the customers with a more sophisticated experience with Microsoft Office Suits, especially Excel.
Method 1 - If Statement Based on Cell Value of a Single Cell in Excel VBA We’ll learn to use an If statement based on the value of a single cell. Let’s try ...
Dataset Overview We have a worksheet called Dataset that contains a table with the Country, Revenue, and Earnings of a company. Our objective today is ...
We will use the sample dataset below to show how to set variables to cell values using VBA. Example 1 - Set Variable to a Single Cell Value Using ...
Here's a quick preview of an open-source QR code generator. Excel VBA: Open Source QR Code Generator (Quick View) Function Generate_QR(QR_Value As ...
Step 1 - Open the Visual Basic Window Press Alt + F11 to open the Visual Basic window. Step 2 - Insert a New UserForm Go to the Insert, ...
Method 1 - Spelling Error While Declaring Variables Look at the following lines of codes. Sub User_Defined_Type_not_Defined() Dim Name As Strng Name = ...
Below is a dataset in the range B2:B12 of a worksheet called Sheet1 that contains some school students' Student IDs, Student Names, Marks, and ...
Quick View: Sub Copy_Single_Cell_Value() Copy_Sheet = "Sheet1" Copy_Cell = "B4" Paste_Sheet = "Sheet2" Paste_Cell = "B4" ...
⧪ Method 1 - Taking the Necessary Inputs Take the necessary inputs to the code. The inputs include The name of the source workbook (Workbook1 in this ...
⧪ Method 1 - Taking Necessary Input Insert the necessary input into the code. Only one input is required in this code: the name of the workbook that we’ll ...
An Overview of the Dataset and VBA Code We have a dataset in the range B3:D12 containing Delivery Dates, Delivery Items, and Quantities. Additionally, ...
Overview: Sub Timestamp_When_a_Macro_is_Run() Timestamp_Sheet = "Sheet1" Timestamp_Column = "B" Set Timestamp_Range = ...
Excel VBA: Convert Formula to Value Automatically (Quick View) Sub Convert_Formula_to_Value_1() Sheet_Name = "Sheet1" Set Cell_Range = ...
VBA provides us with a built-in method called Wait. We’ll use this method to wait until the process completes. The problem is the method Wait takes a fixed ...
Method 1 - Edit the Display Text of a Macro Button in Excel Steps: We have to create a macro button in Excel. We named it "Run the Macro". The ...
Hi Tim, thank you for your valuable response. You can declare the variables this way:
Dim File_Dialog as FileDialog
Set File_Dialog = Application.FileDialog(msoFileDialogFolderPicker)
Dim Sheet_Names(2) as Variant
Sheet_Names(0)=”Sheet1″
Sheet_Names(1)=”Sheet2″
Sheet_Names(2)=”Sheet3″
Dim New_File(2) as Variant
New_File(0)=”New_Sheet1″
New_File(1)=”New_Sheet2″
New_File(2)=”New_Sheet3″
But declaring variables beforehand is not mandatory in VBA. You can directly assign values to them as mentioned in the given codes.
Hi Nico,
Thanks for your response. You can use the FILTER function of Excel for your problem. Check this article for details https://www.exceldemy.com/excel-filter-multiple-criteria/.
Hi Veronika, if your problem isn’t solved yet, you can send the file to my mail or can send an image of your file. I’ll try.
Hi Arjun, the codes are absolutely flawless and there is no reason for them to not work properly. Did you insert the inputs correctly?
Hi Luis,
Thank you for your response. Hope this comes in handy for more people like you.
Hello Sam,
Thank you Sam for your response. It’s working fine now. Thank you again.
Hi Mohammed, Thanks for your response. Insert the name of the text and the color code in the 2nd and 3rd lines of the codes directly.
Hi Man, Thanks in advance. Can you please tell me where exactly the bug is? I have run the code in every way possible and there evolves no error. I think you couldn’t enter the inputs properly. Please go through the article again and then try. If it still doesn’t work, please tell me what exactly the error is.
Hi Dennis,
Thanks for your response. To skip the table name, first, remove the 4th line of the code, that is, Table_Name = InputBox(“Enter the Name of the Table: “).
Then enter the name of the table within the 6th line of the code. For example, if the name of your table is “Table1”, then the line should be: Set tbl = ws.ListObjects(“Table1”).
So the complete code will be:
Sub Add_Empty_Row()
Dim ws As Worksheet
Set ws = ActiveSheet
Dim tbl As ListObject
Set tbl = ws.ListObjects(“Table1”)
tbl.ListRows.Add
End Sub
I think the problem lies in the apostrophes. Use this code instead of yours. It works fine for me.
Sub InsertRowsfromUserInput()
Dim iRow As Long
Dim iCount As Long
Dim i As Long
iCount = InputBox(Prompt:=”How Many Rows to Insert?”)
iRow = InputBox _
(Prompt:=”Where to Insert New Rows? (Enter the Row Number)”)
For i = 1 To iCount
Rows(iRow).EntireRow.Insert
Next i
End Sub
If it still doesn’t work, after pasting the code in the VBA editor, change the apostrophes of the 5th and 7th lines manually. Hope it will work then.
Thank you Ana. It’s difficult to give any suggestions without having a glance at the workbook. Would you please kindly share your workbook with me?