Some help with ranges and offsets

Desmondo

Board Regular
Joined
Feb 27, 2013
Messages
70
I have created a little calculator to make my life a bit easier at work on an excel userform. It is composed essentially of 3 columns and a variable amount of rows dependant on the case. The form is rather like a table where my first 2 rows are headers as below.

Underneath element has drop down list of available components and correct and incorrect are the amounts due versus paid (TextBoxes) . And at the end tells me if overpaid or underpaid.

Some cases i work on go as far back as 2 years and some are only one month. I have a submit button on my userform and a calculate button, calculates the query no problem and submits stores the data in a table like sequence in excel for pasting and coping where necessary into other docs. I would like to be able to click submit and start the next month if there is one like 02/01/2017 - 01/02/2017 then start 02/02/2017 - 01/03/2017 with a clear userform and previous data saved on excel until all months are finished in the period so that i can copy to one word.doc or better. So if 5 or 6 months each should be saved for copying at the end of the case.

Assessment period | From / / | To / / |
Element | Correct Amnt | Incorrect Amnt |

My code so far is not very good but works OK for one month. But can't get my head round how i would use offset and xlup/down it for this Particluar scenario if its possible.


Any help i would be massively grateful.
.

Code:
Private Sub CommandButton2_Click()



Dim irow As Long
Dim lrow As Long
Dim iCntr As Long


lrow = 18


Dim ws As Worksheet


Set ws = Worksheets("Sheet2")
With ws


'Formatting
.Range("A1:C2").Font.Color = vbBlack
.Range("A1:C2").Font.Bold = True
.Range("A1:C19").Font.Size = 10
.Columns("A:C").HorizontalAlignment = xlLeft






.Range("A1") = "Assessment Period"
.Range("B1") = CDate(TextBox15.Value)
.Range("C1") = CDate(TextBox17.Value)
.Range("A2") = "Elements"
.Range("B2") = "Correct Amount"
.Range("C2") = "Incorrect Amount"




'Elements
.Range("A3") = ComboBox1.Value
.Range("A4") = ComboBox2.Value
.Range("A5") = ComboBox3.Value
.Range("A6") = ComboBox4.Value
.Range("A7") = ComboBox5.Value
.Range("A8") = ComboBox6.Value
.Range("A9") = "Total Elements"
.Range("A9:C9").Font.Color = vbBlack
.Range("A9:C9").Font.Bold = True


.Range("A11") = "Earnings of" + " " + "£" + Earnings.Value + " " + " - Disregard of" + " " + ComboBox7.Value + " " + "@" + " " + ComboBox14.Value + "%."
.Range("A12") = ComboBox8.Value
.Range("A13") = ComboBox9.Value
.Range("A14") = ComboBox10.Value
.Range("A15") = ComboBox11.Value
.Range("A17") = "Total Deductions"
.Range("A18") = "Totals"
.Range("A19") = "Amount Overpaid"
.Range("A17:A19").Font.Color = vbBlack
.Range("A17:A19").Font.Bold = True
.Range("A11:C13").Font.Bold = False




'CorrectAmnt
.Range("B3") = c1.Value
.Range("B4") = c2.Value
.Range("B5") = c3.Value
.Range("B6") = c4.Value
.Range("B7") = c5.Value
.Range("B8") = c6.Value
.Range("B9") = c7.Value
'Deds
.Range("B11") = d1.Value
.Range("B12") = d2.Value
.Range("B13") = d3.Value
.Range("B14") = d4.Value
.Range("B15") = d5.Value
.Range("B16") = d6.Value
.Range("B17") = d7.Value
.Range("B18") = cTotal.Value
.Range("B19") = Total.Value
.Range("A18:C18").Font.Bold = True
.Range("A19:B19").Font.Bold = True




'IncorrectAmnt
.Range("C3") = i1.Value
.Range("C4") = i2.Value
.Range("C5") = i3.Value
.Range("C6") = i4.Value
.Range("C7") = i5.Value
.Range("C8") = i6.Value
.Range("C9") = i7.Value
'Deds
.Range("C11") = id1.Value
.Range("C12") = id2.Value
.Range("C13") = id3.Value
.Range("C14") = id4.Value
.Range("C15") = id5.Value
.Range("C16") = id6.Value
.Range("C17") = id7.Value
.Range("C18") = iTotal.Value
.Range("A17:C17").Font.Color = vbBlack
.Range("A17:C17").Font.Bold = True


If d6 > 0.01 Then
.Range("A16") = "Cap applied"
.Range("B16") = d6.Value
End If




End With


For iCntr = lrow To 1 Step -1
If Cells(iCntr, 1) = "" Then
Rows(iCntr).Delete
End If
Next


End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,224,828
Messages
6,181,210
Members
453,023
Latest member
alabaz

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