Correct for misalignment in column for simple calculations

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
688
Hello
There is some misalignment when calculating in column J when button clicked.
Will appreciate if anyone can help me to correct it in code below
For the Following representation

ROWSHIJ
1NAMEAMOUNTTOTAL
2Xxxxx5000
36000
4400015000=sum(H2:H4)This is last used row ref when btn clicked
5yyyyy2000
630005000=sum(H5:H6)This is last used row ref when btn clicked
7xtxtxt3650
82000
93350
10150010500=sum(H7:H10)This is last used row ref when btn clicked

<tbody>
</tbody>

Code:
Private Sub Button_Click()
Dim Ws As Worksheet
Set Ws = Worksheets("Sheet1")

Dim lRec As Long

Dim lstUsdRow As Long
lstUsdRow = (RgsWs.Cells.Find(What:="*", After:=Range("A1"), LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row) + 1

Const StartRow As Long = 2

Dim newRow As Long
        newRow = lstUsdRow 


RgsWs.Cells(lstUsdRow, 7).Value = txtName.Text

For lRec = 1 to CurRec
       Ws.Cells(newRow, 8).Value = Amount$(lRec)
       Ws.Cells(newRow, 9).Formula = "=SUM(H" & StartRow & ":H" & (curRec + 1) & ")"
           newRow = newRow + 1
 Next lRec

End Sub
Thanks
NimishK
 
Last edited:

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Sericom
in OE
Public CurRec as Integer

CurRec = 25 assigned in UF_Ini...()

Jolivanes
Typo Error is ws and not RgsWs
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,226
Members
452,620
Latest member
dsubash

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