Saturday, November 24, 2018
BOLD a Part of the Cell Value
Saturday, November 17, 2018
Replace Excel's Data Validation Drop-down with Smart Userfrom Based Mini Tool
Creating Dropdown from the Validation part of the excel is very easy and very fundamental thing we should know as an Excel Enthusiastic.
When our project required the same list of things to be chosen from the single cell usually make things done with creating the drop-down list from the Data Validation Tool which is inbuilt in Excel.
Now, Sometimes you might have faced or not, but each cell of the column requires the same list of things for selection. I was usually ending up by drag down the dropdown list to the nth row which could be messy sometimes. and it even no looks cool. and you even can't put things apart from the list.
What I have done here is, You don't require a dropdown list at all. Just see the video and you will get what I have done.
The advantage of this tool is you don't need to create hundreds of dropdown in the same column when everything is available to you in just a double-click.
To compile this tool I have required following two scopes.
1. Worksheet Code
2. Userform Design and Codes
You can design the userform and it looks easy not a big deal.
Now let's move towards coding of Worksheet
======
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column = 2 Then
LISTBOX.Show
End If
End Sub
======
I have used BeforeDoubleClick Event to initiate the things.
Now, as we double click on the cell on column two, the Sheet Code will sense it and trigger the event and will force userform to appear.
More to the Second part of the coding
=====
Private Sub UserForm_Initialize()
Application.ScreenUpdating = False
Dim DB As Worksheet
Set DB = Sheets("DATABASE")
Dim I As Long
I = 1
LISTBOX.ListBox1.Clear
Do Until DB.Cells(I, 2).Value = Empty
LISTBOX.ListBox1.AddItem DB.Cells(I, 2).Value
I = I + 1
Loop
Application.ScreenUpdating = True
End Sub
=====
(Above code will take each item of the list from the Place called Database Sheet where you have listed all the details over there with Heading.)
Now DOuble Click even to input userform data into the sheet which the same part of userform coding
======
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
With LISTBOX.ListBox1
If .ListIndex = -1 Then Exit Sub
ActiveCell.Value = .List(.ListIndex)
Cells(ActiveCell.Row, ActiveCell.Column + 1).Activate
Unload LISTBOX
End With
End Sub
======
Now Coding for the Add New Button. this coding will add Item to the list.
Private Sub CommandButton1_Click()
Dim I As Variant
Dim J As Variant
If ActiveCell.Column = 2 Then
I = VBA.InputBox("Please Enter New Tail No.:", "Add New Tail No. in The Database")
If I = vbNullString Then
Exit Sub
Else
J = NewRow("DATABASE", 2)
Sheets("DATABASE").Cells(J, 2).Value = I
Dim DB As Worksheet
Set DB = Sheets("DATABASE")
I = 1
LISTBOX.ListBox1.Clear
Do Until DB.Cells(I, 2).Value = Empty
LISTBOX.ListBox1.AddItem DB.Cells(I, 2).Value
I = I + 1
Loop
End If
end if
end sub
======
So This is it. Please Try. and create more ways to use it in a more effective way.
Thank you
- Kamal Bharakhda
https://www.youtube.com/watch?v=hAEL7TeqOnQ
Friday, November 2, 2018
What is the formula for calculating the inclusive tax amount from a given amount?
Let's answer it with mathematical approach. You might required to use it in the formula or in VBA. This simplification will help you for sure.
Assume few variables
X = Product's Original Amount without Tax
Y = Inclusive Tax Amount (i.e. you're looking)
Z = Product's Amount with Tax or MRP or Included tax amount.
Q = Tax %
-
So basic foundation of product's final amount after tax including is like,
X + Y = Z
Now, Y = ( Q * X ) / 100
So the equation become,
X + ( Q * X ) / 100 = Z
Now solve the above equation to find the value of X
X = ( Z * 100 ) / ( Q + 100 )
And to get the value you required put this value of X back to the initial equation
X + Y = Z
{( Z * 100 ) / ( Q + 100 )} + Y = Z
Now solve for Y,
Y = ( Z * Q ) / ( Q + 100 )
So put known values of Z & Q in the above equation and you will get the required value.
Good day.
Kamal Bharakhda
Friday, October 5, 2018
4 digit PIN Style Login System
Wednesday, August 1, 2018
Sheets Navigator Tool in Excel VBA
There are many ways we can perform navigation through sheets. We can create the shapes to navigate there but hardly, we can only do that for a few sheets. Not for every sheet. So, here I'm coming with a permanent and handsome solution.
My Sheet Navigator
How it looks?
Tuesday, July 17, 2018
Userforms, TexBoxes & Condition Matching in Excel VBA
TextBox1.Value = 10
and
TextBox2.Value = 10
also, if you pass this following coding it gives the wrong result.
If TextBox1.value = TextBox2.value then
MsgBox "Yes They are Equal"
Else
MsgBox "No, They are not Equal"
End if
You will defiantly get the second message and that is, "No, They are not Equal!"
So why does it happens? In Excel VBA, when you are dealing with Userforms, sometimes work demands an use of conditional matching criteria. Just like, IF the value of textbox1 is equal to textbox2 then do something. just like that.
So, Textboxes have always stored values entered in it as String Format. yes even if it's number or not. So, when do we matching the two textboxes based on numbers then we will surely not get the correct result.
So there are two ways to get rid of this.
1. Use Val function
2. Store the Value of TextBoxes into the Worksheet Range.
1. Use of Val Function
If Val(TextBox1.value) = Val(TextBox2.Value) then
MsgBox "Yes They are Equal"
Else
MsgBox "No, They are not Equal"
End if
This time you will receive the First Message.
2. Let's look at this.
'Store the Value of Textboxes into the cell.
Sheets("Sheet1").Range("A1").Value = TextBox1.value
Sheets("Sheet1").Range("A2").Value = TextBox2.value
If Sheets("Sheet1").Range("A1").Value = Sheets("Sheet1").Range("A2").Value then
MsgBox "Yes They are Equal"
Else
MsgBox "No, They are not Equal"
End if
The result will be the same, the first one. It's because of Excel automatically recognize the DataType of the Data entered in the cell. So It will become more accurate and also solves your purpose.
These are the small things. many are knowing and many don't. Who doesn't it's for them.
Thank you!
Kamal Bharakhda
Wednesday, July 4, 2018
Making VBA Development Version Independent Part 1
IsValidPasswordString Function
'Following function will verify if the password string contains following characters or not? Rem : List of Characters Group - ASCII Rem ...
-
Hello Mates, When you work with Userform in Excel VBA, usually sometimes you need to retrieve or reflect currency figure in the Userfo...
-
Making VBA Development Version Independent, will require focussed research and I think it's still "long" to go... ( Here ...
-
Question: Hi All! I considered myself an advanced user until I learned there was an entire world of VBA out there. So now I’m trying to teac...
