Hi, I've been frustrated with this part. I'm trying to population the worksheet with data from a userform. column B is auto-incremented, column D & E are 'most used' debit codes (i only listed 2) and column F is for other debit codes aside from D and E.
Column H and I (only listed 2) are most used Credit codes, column J is for other credit codes.
The most used codes are encoded using textboxes while the 'others' and 'others' amount' are populated thru listboxes
The problem is, there are times when the debit and credit are not equal in # of rows as shown below:
[TABLE="width: 500"]
<tbody>[TR]
[TD]A
Date[/TD]
[TD]B
Serial[/TD]
[TD]C
Transaction No.[/TD]
[TD]D
10104040[/TD]
[TD]E
20201010[/TD]
[TD]F
Others[/TD]
[TD]G
Amount[/TD]
[TD]H
199010[/TD]
[TD]I
199011[/TD]
[TD]J
Others[/TD]
[TD]K
Amount[/TD]
[/TR]
[TR]
[TD]8-7-18[/TD]
[TD]1[/TD]
[TD]2018-08-001[/TD]
[TD]500[/TD]
[TD]500[/TD]
[TD]50201010[/TD]
[TD]1,000[/TD]
[TD]500[/TD]
[TD]500[/TD]
[TD]50215030[/TD]
[TD]500[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]50214020[/TD]
[TD]500[/TD]
[/TR]
</tbody>[/TABLE]
some of my codes:
I'm not actually good in programming but our accounting department requested this from me.
I think the problem is the referencing to the lastrow.
Column H and I (only listed 2) are most used Credit codes, column J is for other credit codes.
The most used codes are encoded using textboxes while the 'others' and 'others' amount' are populated thru listboxes
The problem is, there are times when the debit and credit are not equal in # of rows as shown below:
[TABLE="width: 500"]
<tbody>[TR]
[TD]A
Date[/TD]
[TD]B
Serial[/TD]
[TD]C
Transaction No.[/TD]
[TD]D
10104040[/TD]
[TD]E
20201010[/TD]
[TD]F
Others[/TD]
[TD]G
Amount[/TD]
[TD]H
199010[/TD]
[TD]I
199011[/TD]
[TD]J
Others[/TD]
[TD]K
Amount[/TD]
[/TR]
[TR]
[TD]8-7-18[/TD]
[TD]1[/TD]
[TD]2018-08-001[/TD]
[TD]500[/TD]
[TD]500[/TD]
[TD]50201010[/TD]
[TD]1,000[/TD]
[TD]500[/TD]
[TD]500[/TD]
[TD]50215030[/TD]
[TD]500[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]50214020[/TD]
[TD]500[/TD]
[/TR]
</tbody>[/TABLE]
some of my codes:
Code:
lrow = ws.Range("B" & Rows.Count).End(xlUp).Row + 1 'gets the lastrow +1
lrow2 = ws.Range("B" & Rows.Count).End(xlUp).Row - 6 'Since the start of my database is on row 7 (1-6 are headers and stuffs)
ws.Range("A" & lrow).value = Format(CDate(Me.txt_Date.value), "mm/dd/yyyy")
ws.Range("B" & lrow).value = lrow2 + 1
ws.Range("C" & lrow).value = txt_transac_ID.value
ws.Range("D" & lrow).value = Format(Me.TextBox1.value, "#,##0.00")
ws.Range("E" & lrow).value = Format(Me.TextBox2.value, "#,##0.00")
dim i as integer
For i=0 to listbox1.listcount -1 'listbox for debit
If ws.Range("B" & lrow).value = "" Then
ws.Range("B" & lrow).value = lrow2 + 1
ws.Range("C" & lrow).value = txt_transac_ID.value
ws.Range("F" & lrow).value = ListBox1.List(i, 0)
ws.Range("G" & lrow).value = ListBox1.List(i, 1)
Else
ws.Range("F" & lrow).value = ListBox1.List(i, 0)
ws.Range("G" & lrow).value = ListBox1.List(i, 1)
End If
Next
ws.Range("H" & lrow).value = Format(Me.TextBox3.value, "#,##0.00")
ws.Range("I" & lrow).value = Format(Me.TextBox4.value, "#,##0.00")
dim j as integer
for j = 0 to listbox2.listcount - 1 'listbox for credit
If ws.Range("B" & lrow).value = "" Then
ws.Range("B" & lrow).value = lrow2 + 1
ws.Range("C" & lrow).value = txt_transac_ID.value
ws.Range("J" & lrow).value = ListBox1.List(j, 0)
ws.Range("K" & lrow).value = ListBox1.List(j, 1)
Else
ws.Range("J" & lrow).value = ListBox1.List(j, 0)
ws.Range("K" & lrow).value = Listbox1.List(j, 1)
End If
Next
I think the problem is the referencing to the lastrow.
Last edited: