Question: I have a project on excel. I did add button but it need more functionality. When I add a new data this button must do
I have a project on excel. I did add button but it need more functionality. When I add a new data this button must do this:
Match the value on A column (A value textbox=txtA) first, then alphabetically add relative to G column(G value textbox= txtG). (This is my logic. If there is another alternative logic I would like to hear that)
Example
___A_________B_C_D_E_F_______G______
1-)Mdr------------- Blabla -------------a10(example values)
2-)Mdr------------- Blabla------------- c42
3-)Mdr------------- Blabla------------- d56
4-)Mdr------------- Blabla------------- e15
5-)Blm------------- Blabla------------- a14
6-)Blm------------- Blabla------------- f48
7-)Blm------------- Blabla------------- h60
8-)Blm------------- Blabla------------- j72
Ex: When I enter A, txtA on textbox "Blm" and G,txtG on textbox "f49" or "g16" it must be added on after 6th row. Also other cells will be filled too but add function must insert new data's row depend only A and G column.
My question that: what is this function codes and compatible with my code ?
Or which new code version for this function ?
My codes (add function work clearly):
Private Sub cmdSave_Click()
Dim sh As Worksheet
Set sh = ThisWorkBook.Sheets("Worksheet")
Dim le As Long
lr = Sheets("Worksheet").Range("A" & Rows.Count).End(xlUp).Row
'''''''''''''''''''''''''''''''''''''I worked this part for this function but function does not work clearly''''''''''''''''''''''''''''''''''''''''''''''
Dim sNewName As String
Dim rEmpList As Range
Set rEmpList = Sheets("Worksheet").Range("A:A")
sNewName = txtA.Value
le = Application.WorksheetFunction.Match (sNewName, rEmpList,1)
Rows(le+1).Insert
Range("G" & le + 1).Value = sNewName
'''''''''''''''''''''''Add data in excel sheet this part works clearly''''''''''''''''''''''''''''''''''''''
with sh
.Cells(le + 1, "A").Value = Me.txtA.Value
.Cells(le + 1, "B").Value = Me.txtB.Value
.Cells(le + 1, "C").Value = Me.txtC.Value
.Cells(le + 1, "D").Value = Me.txtD.Value
.Cells(le + 1, "E").Value = Me.txtE.Value
.Cells(le + 1, "F").Value = Me.txtF.Value
.Cells(le + 1, "G").Value = Me.txtG.Value
.Cells(le + 1, "H").Value = Me.txtH.Value
.Cells(le + 1, "I").Value = Me.txtI.Value
.Cells(le + 1, "J").Value = Me.txtJ.Value
.Cells(le + 1, "L").Value = Me.txtL.Value
.Cells(le + 1, "M").Value = Me.txtM.Value
.Cells(le + 1, "N").Value = Me.txtN.Value
.Cells(le + 1, "O").Value = Me.txtO.Value
.Cells(le + 1, "P").Value = Me.txtP.Value
Cells(le + 1, "Q").Value = Me.txtQ.Value
Cells(le + 1, "R").Value = Me.txtR.Value
Cells(le + 1, "S").Value = Me.txtS.Value
Cells(le + 1, "T").Value = Me.txtT.Value
Cells(le + 1, "U").Value = Me.txtU.Value
Cells(le + 1, "W").Value = Me.txtW.Value
Cells(le + 1, "X").Value = Me.txtX.Value
Cells(le + 1, "Y").Value = Me.txtY.Value
Cells(le + 1, "Z").Value = Me.txtZ.Value
Cells(le + 1, "AA").Value = Me.txtAA.Value
Cells(le + 1, "AB").Value = Me.txtAB.Value
Cells(le + 1, "AC").Value = Me.txtAC.Value
Cells(le + 1, "AD").Value = Me.txtAD.Value
Cells(le + 1, "AE").Value = Me.txtAE.Value
Cells(le + 1, "AF").Value = Me.txtAF.Value
Cells(le + 1, "K").Value = Me.txtK.Value
I didn't copy paste the codes. So if there is any word mistake please ignore this.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
