Hi All,
I attached a sheet for your reference. Please check.
I am trying to write a macro which will help to divide a whole number by 40 and than place the reminder in next rows kindly help for the same.
Thanks,
Vignesh kumar.S
Hi All,
I attached a sheet for your reference. Please check.
I am trying to write a macro which will help to divide a whole number by 40 and than place the reminder in next rows kindly help for the same.
Thanks,
Vignesh kumar.S
Last edited by vigneshkumar; 04-02-2013 at 12:53 AM.
Hi, vigneshkumar,
give this code a try:
Ciao,![]()
Sub 911415() Dim lngCounter As Long Dim lngRow As Long Dim lngLastCol As Long Dim lngMod As Long Dim blnWrite As Boolean Const clngDATA As Long = 4 Const clngDIV As Long = 40 lngRow = clngDATA For lngCounter = 4 To Cells(clngDATA, Columns.Count).End(xlToLeft).Column lngMod = Int(Cells(clngDATA, lngCounter).Value / clngDIV) If lngMod > 0 Then lngRow = lngRow + 1 With Cells(lngRow, lngCounter) .Value = Cells(clngDATA, lngCounter).Value Mod clngDIV .Offset(0, -lngMod).Resize(1, lngMod).Value = clngDIV End With End If Next lngCounter End Sub
Holger
Use Code-Tags for showing your code: [code] Your Code here [/code]
Please mark your question Solved if there has been offered a solution that works fine for you
Hi Holger,
Thanks a lot for your quick response.
i will rephrase my question i am trying to split any number in the form of 40 for example take a number 90 this number i am trying to split as 40, 40, 10 or take a number 129 this number should be split into 40, 40, 40,9 like this, hope you got what I am looking for. Thanks for ur help,
regards,
Vignesh
Hi, Vignesh ,
just copy sheet1, clear the rows under Row 4 and then run the macro.
What does the macro do? Personally I wonīt let data start in the middle of nowhere but as this is done in the attachment the code takes care of the situation in Sheet1 and hopefully doubles up what I thought was the desired outcome.i will rephrase my question i am trying to split any number in the form of 40
Ciao,
Holger
Hi Holger,
The macro should take care of splitting the particular number in 40s , for example 90 should get split into 40, 40 and the left out number 10 should be placed in next row. Thanks and if i am confusing you i'm really sorry
Thanks,
Vignesh
Hi, Vignesh,
Whatīs the good of posting a workbook which should show the situation as is and as desired and then come back because you want something else than what is shown in the workbook? Even with what you tell right now itīs unclear to me what you want: all data in one row or all data cascading down under the original? Only show numbers if they are greater than 40 or show all rests?if i am confusing
Regarding your attached workbook and the sample given there:
![]()
Sub EF911415_2a() Dim lngCounter As Long Dim lngRow As Long Dim lngLastCol As Long Dim lngMod As Long Dim blnWrite As Boolean Const clngDATA As Long = 4 Const clngDIV As Long = 40 lngRow = clngDATA For lngCounter = 4 To Cells(clngDATA, Columns.Count).End(xlToLeft).Column lngMod = Int(Cells(clngDATA, lngCounter).Value / clngDIV) If lngMod > 0 Then lngRow = lngRow + 1 Cells(lngRow, lngCounter).Value = Cells(clngDATA, lngCounter).Value Mod clngDIV End If Next lngCounter End Sub
![]()
Sub EF911415_2b() Dim lngCounter As Long Dim lngRow As Long Dim lngLastCol As Long Dim lngMod As Long Dim blnWrite As Boolean Const clngDATA As Long = 4 Const clngDIV As Long = 40 lngRow = clngDATA + 1 For lngCounter = 4 To Cells(clngDATA, Columns.Count).End(xlToLeft).Column lngMod = Int(Cells(clngDATA, lngCounter).Value / clngDIV) If lngMod > 0 Then Cells(lngRow, lngCounter).Value = Cells(clngDATA, lngCounter).Value Mod clngDIV End If Next lngCounter End Sub
![]()
Sub EF911415_2c() Dim lngCounter As Long Dim lngRow As Long Dim lngLastCol As Long Dim lngMod As Long Dim blnWrite As Boolean Const clngDATA As Long = 4 Const clngDIV As Long = 40 lngRow = clngDATA + 1 For lngCounter = 4 To Cells(clngDATA, Columns.Count).End(xlToLeft).Column If Cells(clngDATA, lngCounter).Value > 0 Then lngMod = Int(Cells(clngDATA, lngCounter).Value / clngDIV) Cells(lngRow, lngCounter).Value = Cells(clngDATA, lngCounter).Value Mod clngDIV End If Next lngCounter End Sub
No, as the attached workbook showed numbers in one row and the results underneath.as I mentioned before keep a number 90 in one cell b6 then if i run the macro than it should automatically place in cell c4 40 in cell c5 40 and in cell c6 10
Holger
Hi Holger,
I need help only in the splitting and placing the numbers in a cell, as I mentioned before keep a number 90 in one cell b6 then if i run the macro than it should automatically place in cell c4 40 in cell c5 40 and in cell c6 10, hope it helps u to understand my problem.
Thanks,
VIgnesh
Hi HaHobe,
Thanks a lot, I am able to get the required result, only thing is number 40 is not visible, I will try to resolve it on my own. Thanks for ur great help.
Regards,
Vignesh
Hi, Vignesh,
the first macro code showed a way using Offset and Resize (although result was in a row, not a column).
Ciao,
Holger
Thanks for the great help excel guru
You are really a expert.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks