Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-22-2017, 01:08 AM
ewso ewso is offline Add only first numbers in each cell Windows 10 Add only first numbers in each cell Office 2016
Advanced Beginner
Add only first numbers in each cell
 
Join Date: Nov 2016
Posts: 80
ewso is on a distinguished road
Default


Quote:
Originally Posted by gmayor View Post
It is easy enough with a macro. The following assumes the result will go in the last cell in the column containing the cursor and that there are no merged/split cells in the table.

Code:
Sub CountNums()
Dim oTable As Table
Dim lngCount As Long: lngCount = 0
Dim oCell As Cell
Dim oRng As Range
Dim i As Integer
Dim iCol As Integer
Dim iRow As Integer

Set oTable = Selection.Tables(1)
    iRow = oTable.Rows.Count
    If Selection.InRange(oTable.Range) = True Then
        iCol = Selection.Cells(1).ColumnIndex
        For i = 1 To iRow - 1
            lngCount = lngCount + Split(oTable.Columns(iCol).Cells(i).Range.Text, Chr(32))(0)
        Next i
        Set oRng = oTable.Columns(iCol).Cells(iRow).Range
        oRng.End = oRng.End - 1
        oRng.Text = lngCount
    End If
lbl_Exit:
    Set oCell = Nothing
    Set oRng = Nothing
    Exit Sub
End Sub

Hi, thanks for the code, but I get an error when I run it. It says...

Compile error:
User-defined type not defined


What could be wrong?
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Add only first numbers in each cell Sorting numbers within cell michaelst Excel 9 04-22-2017 10:51 PM
Difference between 2 numbers in same cell Neila1982 Excel 1 02-12-2017 01:40 AM
Add only first numbers in each cell Add Numbers from One or Another Cell Kilch Excel 3 01-31-2017 12:55 PM
Search a cell that contains words and numbers and convert the numbers to metric Carchee Excel Programming 36 10-08-2014 03:16 PM
Add only first numbers in each cell adding numbers in same cell jetdude68 Word Tables 1 07-20-2010 12:30 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:17 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft