Saving and Searching data to and through different Worksheet with User Form

Yeft

New Member
Joined
Jan 6, 2023
Messages
35
Office Version
  1. 365
Platform
  1. Windows
Hello There!
I need to save data and search for it through different worksheets in a work book via User Form. Data has to be saved depending on what section it belongs to
Each section's name (selected From a Combo Box ) would have a respective worksheet. When searching for data It should pulled out straight to the User Form.
Any Help on this issue would be much appreciated, as I tried and it does not work. Please see below the code I made for saving data:

VBA Code:
Sub cmdSave_Click()
Dim shBox As Worksheet
Dim iCurrentRow As Integer
Dim sBoxName As String


sBoxName = CLng(Control7.SelectedItem)                                       'Control7" (Combo Box to select the section)
Set shBox = ThisWorkbook.Sheets(sBoxName)

iCurrentRow = shBox.Range("A" & Application.Rows.Count).End(xlUp).Row + 1
 
With shBox

.Cells(iCurrentRow, 1) = iCurrentRow - 1
.Cells(iCurrentRow, 3) = Control2.Text
.Cells(iCurrentRow, 4) = Control3.Text
.Cells(iCurrentRow, 5) = Control4.Text
.Cells(iCurrentRow, 6) = Control5.Text
.Cells(iCurrentRow, 7) = Control6.Text
.Cells(iCurrentRow, 8) = Control7.Text
.Cells(iCurrentRow, 9) = Control8.Text
.Cells(iCurrentRow, 10) = Control9.Text
.Cells(iCurrentRow, 11) = Control10.Text
.Cells(iCurrentRow, 12) = Control11.Text
.Cells(iCurrentRow, 13) = Control12.Text
.Cells(iCurrentRow, 14) = Control13.Text
.Cells(iCurrentRow, 15) = Control14.Text
.Cells(iCurrentRow, 16) = Control15.Text
.Cells(iCurrentRow, 17) = Control16.Text
.Cells(iCurrentRow, 18) = Control17.Text
.Cells(iCurrentRow, 19) = Control18.Text

End With

MsgBox "Data added succesfully!"

End Sub

[ATTACH type="full"]112262[/ATTACH]
 

Attachments

  • User Form Issue.jpg
    User Form Issue.jpg
    38.2 KB · Views: 11

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi,
firstly, there is an error at start of your code with this line

VBA Code:
sBoxName = CLng(Control7.SelectedItem)

the combobox control does not have the SelectedItem property. Also, you are coercing string data of the control to long data type & then passing this to a variable declared as string data type which is not really going to work.

But this aside, it would be helpful to forum if you could place copy of your workbook (with dummy data) on a file sharing site like dropbox & provide a link to it here.

Dave
 
Upvote 1
Solution
Hello Dave,

Thank you very much for the suggestion. I'm new to VBA, and still make lots of mistakes.
I finally went around the issue and fixed it.

I have now a different issue, but I think I'll need to open a different thread. and I'm still struggling on how to send
my file or a link for you guys to access.

Thank you so much!
 
Upvote 0

Forum statistics

Threads
1,223,702
Messages
6,173,957
Members
452,539
Latest member
delvey

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