Cross sum from a number but cross sum should total to one digit

0 votes

I want to get cross sum of numbers rounding to one digit.

For example 789 = 24 but I want to get 6 from the first time.

Sub quersumme()

Dim a As Integer
Dim ln As Integer
Dim mystring As Integer


On Error Resume Next
mystring = Cells(1, 1).Value

a = 0
ln = Len(mystring)

For i = 1 To ln
a = a + Mid(mystring, i, 1)


Next i

Cells(1, 2) = a

End Sub
Feb 26, 2023 in Others by narikkadan
• 63,600 points
465 views

1 answer to this question.

0 votes

Try this:

Option Explicit

Sub Quersumme_OneDigit()

    Dim res As Long
    res = Cells(1, 1).Value
    
    Do
        res = Quersumme(res)
    Loop Until res < 10

    Cells(1, 2) = res

End Sub

Function Quersumme(ByVal Zahl As Double) As Double
    Dim i  As Long
    Dim Summe As Double

    For i = 1 To Len(CStr(Zahl))
        Summe = Summe + Mid(CStr(Zahl), i, 1)
    Next
    Quersumme = Summe
End Function
answered Mar 17, 2023 by Kithuzzz
• 38,000 points

Related Questions In Others

0 votes
0 answers

How to drop all tables from a database with one SQL query?

What if we don't want to type ...READ MORE

May 28, 2022 in Others by Sohail
• 3,040 points
370 views
0 votes
0 answers

How to drop all tables from a database with one SQL query?

drop all tables without typing name. Is ...READ MORE

Jun 7, 2022 in Others by polo
• 1,480 points
287 views
+1 vote
1 answer

Excel or Google formula to count occurrences of an 8-digit number within a text string

To match an eight-digit number, you may ...READ MORE

answered Dec 24, 2022 in Others by narikkadan
• 63,600 points
990 views
0 votes
1 answer

2D rotation of an object along a custom axis

Use this: Option Explicit Type ObjLocData ...READ MORE

answered Jan 31, 2023 in Others by narikkadan
• 63,600 points
376 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
1,212 views
0 votes
1 answer

How to load file to Excel Power query from SFTP site

Currently, I don't think there is a ...READ MORE

answered Dec 3, 2018 in Power BI by Upasana
• 8,620 points
3,662 views
0 votes
1 answer

Using VBA Excel to create a gramatically correct list

The Excel AND function is a logical ...READ MORE

answered Feb 9, 2022 in Others by gaurav
• 23,260 points
908 views
0 votes
1 answer

Excel VBA: how to find a description from an AD-group

First add the 'description' property to your ...READ MORE

answered Feb 16, 2023 in Others by Kithuzzz
• 38,000 points
970 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP