Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 02-14-2022, 10:56 PM
ranjan ranjan is offline Removing  Identical Rows Windows 10 Removing  Identical Rows Office 2019
Advanced Beginner
Removing  Identical Rows
 
Join Date: May 2021
Posts: 80
ranjan is on a distinguished road
Default

Hi,

Complie Error: For without next....


Please review the below error, after a removing identical rows then calculate the wc for column 3.

Range is from 4th row & 3rd column and display a msg as "WC"

Code:
Public Sub DeleteDuplicatesCol3()

  Dim xTable As Table, xRow As Range, xStr As String, xDic As Object
  Dim I As Long, J As Long, KK As Long, xNum As Long, iRow As Long, iRows As Long
  Dim aRng As Range, cRng As Range, lWords As Long, lRows As Long, aCell As Cell
  Dim nWordsCount As Long
  Dim nCharCount As Long

  'Application.ScreenUpdating = False
  Set xDic = CreateObject("Scripting.Dictionary")
  If Selection.Tables.Count = 0 Then
    MsgBox "Macro must be run when a table is selected"
    Exit Sub
  Else
    Set xTable = Selection.Tables(1)
    iRows = xTable.Rows.Count
    For I = iRows To 4 Step -1
      Set aRng = xTable.Cell(I, 2).Range
      For iRow = 4 To I - 1
        Set cRng = xTable.Cell(iRow, 2).Range
        If aRng.Text = cRng.Text Then
          xTable.Rows(I).Delete
          lRows = lRows + 1
          Exit For
        End If
      Next iRow
    Next I
  End If
  
  Set aRng = ActiveDocument.Range(xTable.Rows(4).Range.Start, xTable.Range.End)
  
For Each aCell In aRng.Cells

 If aCell.ColumnIndex = 3 Then

nWordsCount = aRng.ComputeStatistics(wdStatisticWords)
nCharCount = aRng.ComputeStatistics(wdStatisticCharacters)
 
    Application.ScreenUpdating = True

    MsgBox "Word count in column 3: " & "The entire doc contains: " & vbCrLf & nWordsCount & " words and" & vbCrLf & _
           nCharCount & " characters without spaces", , "Word Count"

  End If

  
  End Sub

Last edited by ranjan; 02-14-2022 at 10:58 PM. Reason: Code reviewed & getting compile error
Reply With Quote
 

Tags
delete, identical



Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing  Identical Rows Removing rows when mail merging Richystab Mail Merge 3 12-07-2020 03:05 AM
Identical computers MeCasa Office 0 09-23-2019 03:43 PM
Removing duplicate rows when identical value in a column ballpoint Excel 1 01-05-2018 08:54 AM
how to delete every blank and non-numeric rows without removing the header enuff Excel 3 08-24-2017 05:56 AM
Removing  Identical Rows How to find an identical sentences? Bill K Word 1 12-03-2015 12:16 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:00 PM.


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