request for code

ramebits

New Member
Joined
Aug 30, 2018
Messages
6
Userform have two combobox with subject name and other combox2 have year and one textbox in combobox i select subject "English" and from Combobox2 select year 2024 and typed numeric value in textbox I want text box value go to in excel with selected subject and year. subjects are in A2:A16 and years are in B1:G1
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hello @ramebits!
For beginners, the most primitive code.
VBA Code:
Option Explicit

Private Sub SubmitButton_Click()

    If ComboBox1.Value = "" Then
        MsgBox "Please Select a Subject", vbCritical
        Exit Sub
    End If

    If ComboBox2.Value = "" Then
        MsgBox "Please Select a Year", vbCritical
        Exit Sub
    End If

    If TextBox1.Value = "" Then
        MsgBox "Please Enter the some Numeric value", vbCritical
        Exit Sub
    End If

    With ThisWorkbook.Worksheets("Sheet1")
        Dim nextRow As Long
        nextRow = .Range("A" & .Rows.Count).End(xlUp).Row + 1
        MsgBox nextRow

        Dim nextCol As Long
        nextCol = .Cells(1, .Columns.Count).End(xlToLeft).Column + 1
        MsgBox nextCol

        .Cells(nextRow, 1).Value = ComboBox1.Value
        .Cells(nextRow + 1, 1).Value = TextBox1.Value
        .Cells(1, nextCol).Value = ComboBox2.Value
    End With

End Sub

Private Sub UserForm_Initialize()
    ComboBox1.List = Array("English", "French", "Italian", "Spanish", "German")
    ComboBox2.List = Array("2024", "2025", "2026", "2027", "1979")
    ComboBox1.SetFocus
End Sub
Good luck.
 
Upvote 0
its not working
textbox value not appear in proper place subjects (English, Hindi, Maths, Sociology etc. are in B2:B4 which reflect in B2:B46 and years (2019-20, 2020-21, 2021-22 etc. are in C1:F1 which reflect in combobox2 but when I choose subject hindi (which is in B3 subject and Year 2020-21 (Which in D1) when I put 2 in textbox1 its not reflect in proper place (proper place is D3)
Suppose I select B2 subject English form combobox1 and Year D1 - 2021-21 from combobox2, the value of textbox is 1 which should be comes in D2
A B C D E F
1 S.No Subject 2020-21 2021-22 2022-23 2023-24
2 1 Eng - 1 - -
3 2 Hindi - - - -
4 3 Math - - - -
 
Upvote 0
Well, as you explained, you got this result. Continue to refine it yourself. Good luck.
 
Upvote 0
Try this :

VBA Code:
Option Explicit


Private Sub CommandButton1_Click()

    If ComboBox1.Value = "" Then
        MsgBox "Please Select a Subject", vbCritical
        Exit Sub
    End If

    If ComboBox2.Value = "" Then
        MsgBox "Please Select a Year", vbCritical
        Exit Sub
    End If

    If TextBox1.Value = "" Then
        MsgBox "Please Enter the some Numeric value", vbCritical
        Exit Sub
    End If

    With ThisWorkbook.Worksheets("Sheet1")
        Dim nextRow As Long
        nextRow = .Range("A" & .Rows.Count).End(xlUp).Row + 1
        MsgBox nextRow

        Dim nextCol As Long
        nextCol = .Cells(1, .Columns.Count).End(xlToLeft).Column + 1
        MsgBox nextCol

        .Cells(nextRow, 1).Value = ComboBox1.Value
        .Cells(nextRow, 4).Value = TextBox1.Value
        .Cells(nextRow, 2).Value = ComboBox2.Value
    End With

End Sub

Private Sub UserForm_Initialize()
    ComboBox1.List = Array("English", "French", "Italian", "Spanish", "German")
    ComboBox2.List = Array("2024", "2025", "2026", "2027", "1979")
    ComboBox1.SetFocus
End Sub
 
Upvote 0

Forum statistics

Threads
1,226,281
Messages
6,190,044
Members
453,589
Latest member
frdranger25401

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top