Correct for misalignment in column for simple calculations

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
612
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:

Some videos you may like

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

sericom

Well-known Member
Joined
Jan 19, 2006
Messages
915
Not sure of your problem, but I can't see where CurRec is assigned a value.
 

NimishK

Well-known Member
Joined
Sep 4, 2015
Messages
612
Sericom
in OE
Public CurRec as Integer

CurRec = 25 assigned in UF_Ini...()

Jolivanes
Typo Error is ws and not RgsWs
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,122,471
Messages
5,596,347
Members
414,060
Latest member
hermanseck

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
Top