Hi guys and gals I have been a silent user of this site for sometime usually finding something close enough to my means that I havent had to post so far but I have now hit a (hopefully simple) snag.
I work for a community organisation, one function of which is we distribute vouchers to those in hard times. We need to keep records of this data and do various other reporting. I have created a userform to capture this data which saves the collected data to a hidden worksheet. Each time a person recieves assistance we have a reference number, but an individual may receive more than one type of assistance so on the data saved to the hidden worksheet needs to have the reference number in column A... otherwise when data is entered in the following instance it searchs for the first blank cell in column A and writes over the other data in columns b, c and d.
Currently it looks like...
*** No Voucher type Voucher No. Amount
B001 "Food" 1234 80
"Clothing" A1111 35
"Pharmacy" Pham11 30
Where it should look like...
*** No Voucher type Voucher No. Amount
B001 "Food" 1234 80
B001 "Clothing" A1111 35
B001 "Pharmacy" Pham11 30
The code am currently playing with is...
Textbox28 is the reference number and I have tried to use an If expression to have it do the following (see comments)
Private Sub cboSave_Click()
Dim LastRow As Object
Set LastRow = Sheets("Voucher Data").Range("a65536").End(xlUp)
'Enters saved values into mastersheet
LastRow.Offset(1, 0).Value = TextBox28.Text 'this is the reference no
LastRow.Offset(1, 1).Value = cbovoucher1.Text 'voucher type
LastRow.Offset(1, 2).Value = TextBox1.Text 'voucher number
LastRow.Offset(1, 3).Value = TextBox14.Text 'amount
LastRow.Offset(2, 1).Value = ComboBox1.Text 'voucher type
LastRow.Offset(2, 2).Value = TextBox2.Text 'voucher number
LastRow.Offset(2, 3).Value = TextBox15.Text 'voucher amount
If UserForm1.TextBox2.Value = True Then 'if a value is present then
LastRow.Offset(1, 0).Value = TextBox28.Text 'display the value in textbox28 in the corresponding row
Else
End If
LastRow.Offset(3, 1).Value = ComboBox2.Text 'voucher type
LastRow.Offset(3, 2).Value = TextBox3.Text 'voucher number
LastRow.Offset(3, 3).Value = TextBox14.Text 'voucher amount
If UserForm1.ComboBox2.Value = True Then
LastRow.Offset(1, 0).Value = TextBox28.Text 'reference number
Else
End If
LastRow.Offset(4, 1).Value = ComboBox3.Text
LastRow.Offset(4, 2).Value = TextBox4.Text
LastRow.Offset(4, 3).Value = TextBox17.Text
If UserForm1.ComboBox3.Value = True Then
LastRow.Offset(1, 0).Value = TextBox28.Text
Else
End If
MsgBox "Data Saved"
Unload Me
End Sub
Also a I have a number of combobox's that reference a certain cell range, however I have had to currently write them out as (for eg.)
Me.ComboBox1.RowSource = "Source!A1:A10"
Me.ComboBox2.RowSource = "Source!A1:A10"
Me.ComboBox3.RowSource = "Source!A1:A10"
I have tried doing something like... but obviously it doesnt work.
Private Sub Combolist()
Dim X As Long
Application.ScreenUpdating = False
For W = 0 To 10
Me.ComboBox(W).RowSource = "Source!A1:A10"
Any assistance would be greatly appreciated.
Regards
I work for a community organisation, one function of which is we distribute vouchers to those in hard times. We need to keep records of this data and do various other reporting. I have created a userform to capture this data which saves the collected data to a hidden worksheet. Each time a person recieves assistance we have a reference number, but an individual may receive more than one type of assistance so on the data saved to the hidden worksheet needs to have the reference number in column A... otherwise when data is entered in the following instance it searchs for the first blank cell in column A and writes over the other data in columns b, c and d.
Currently it looks like...
*** No Voucher type Voucher No. Amount
B001 "Food" 1234 80
"Clothing" A1111 35
"Pharmacy" Pham11 30
Where it should look like...
*** No Voucher type Voucher No. Amount
B001 "Food" 1234 80
B001 "Clothing" A1111 35
B001 "Pharmacy" Pham11 30
The code am currently playing with is...
Textbox28 is the reference number and I have tried to use an If expression to have it do the following (see comments)
Private Sub cboSave_Click()
Dim LastRow As Object
Set LastRow = Sheets("Voucher Data").Range("a65536").End(xlUp)
'Enters saved values into mastersheet
LastRow.Offset(1, 0).Value = TextBox28.Text 'this is the reference no
LastRow.Offset(1, 1).Value = cbovoucher1.Text 'voucher type
LastRow.Offset(1, 2).Value = TextBox1.Text 'voucher number
LastRow.Offset(1, 3).Value = TextBox14.Text 'amount
LastRow.Offset(2, 1).Value = ComboBox1.Text 'voucher type
LastRow.Offset(2, 2).Value = TextBox2.Text 'voucher number
LastRow.Offset(2, 3).Value = TextBox15.Text 'voucher amount
If UserForm1.TextBox2.Value = True Then 'if a value is present then
LastRow.Offset(1, 0).Value = TextBox28.Text 'display the value in textbox28 in the corresponding row
Else
End If
LastRow.Offset(3, 1).Value = ComboBox2.Text 'voucher type
LastRow.Offset(3, 2).Value = TextBox3.Text 'voucher number
LastRow.Offset(3, 3).Value = TextBox14.Text 'voucher amount
If UserForm1.ComboBox2.Value = True Then
LastRow.Offset(1, 0).Value = TextBox28.Text 'reference number
Else
End If
LastRow.Offset(4, 1).Value = ComboBox3.Text
LastRow.Offset(4, 2).Value = TextBox4.Text
LastRow.Offset(4, 3).Value = TextBox17.Text
If UserForm1.ComboBox3.Value = True Then
LastRow.Offset(1, 0).Value = TextBox28.Text
Else
End If
MsgBox "Data Saved"
Unload Me
End Sub
Also a I have a number of combobox's that reference a certain cell range, however I have had to currently write them out as (for eg.)
Me.ComboBox1.RowSource = "Source!A1:A10"
Me.ComboBox2.RowSource = "Source!A1:A10"
Me.ComboBox3.RowSource = "Source!A1:A10"
I have tried doing something like... but obviously it doesnt work.
Private Sub Combolist()
Dim X As Long
Application.ScreenUpdating = False
For W = 0 To 10
Me.ComboBox(W).RowSource = "Source!A1:A10"
Any assistance would be greatly appreciated.
Regards