Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Find consecutively and copy

I need to scan all used cells in column C from top to bottom and for those
with more than one occurence copy the cell contents one column to the left
and add as many "i" at the end as that cell is an occurence of the searched
cell or the occurence number.

Option Explicit
Sub wwweee()

Dim OccurCount As Long
Dim CellFound As Range
Dim i As Integer

For i = 1 To Range("C3").SpecialCells(xlLastCell).Row

For OccurCount = 1 To WorksheetFunction.CountIf(Columns(3), Cells(i, 3))
Set CellFound = Columns(3).Find(What:=Cells(i, 3).Value,
After:=Cells(i,3), LookIn:=xlValues, LookAt:=xlPart,
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)

Cells(i, 2).Value = Cells(i, 3).Value & OccurCount - 1
Next OccurCount
Next i
End Sub

Thanks in davance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Find consecutively and copy

Can you use a formula like this in D1:
=C1 & "-(" & COUNTIF($C$1:C1,C1) & ")"
And drag down?

If this is close, maybe you can modify this code:

Option Explicit
Sub testme01()

Dim LastRow As Long
Dim wks As Worksheet

Set wks = Worksheets("Sheet1")

With wks
LastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
With .Range("D1:d" & LastRow)
.FormulaR1C1 _
= "=rc[-1] & ""-("" & countif(r1c3:rc[-1],rc[-1]) & "")"""
.Value = .Value
End With
End With

End Sub


LuisE wrote:

I need to scan all used cells in column C from top to bottom and for those
with more than one occurence copy the cell contents one column to the left
and add as many "i" at the end as that cell is an occurence of the searched
cell or the occurence number.

Option Explicit
Sub wwweee()

Dim OccurCount As Long
Dim CellFound As Range
Dim i As Integer

For i = 1 To Range("C3").SpecialCells(xlLastCell).Row

For OccurCount = 1 To WorksheetFunction.CountIf(Columns(3), Cells(i, 3))
Set CellFound = Columns(3).Find(What:=Cells(i, 3).Value,
After:=Cells(i,3), LookIn:=xlValues, LookAt:=xlPart,
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)

Cells(i, 2).Value = Cells(i, 3).Value & OccurCount - 1
Next OccurCount
Next i
End Sub

Thanks in davance


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default Find consecutively and copy

Thanks Dave. You are always very helful.

Could you please take a look at this post and help me?

"Shif cells to the right and down within limits"

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you REALLY get Excel to Autonumber consecutively? Otto Excel Discussion (Misc queries) 6 September 24th 08 01:01 AM
Summing every 7 cells consecutively [email protected] Excel Worksheet Functions 3 June 10th 08 04:23 PM
how do I consecutively number invoices parkfield Excel Discussion (Misc queries) 2 December 7th 07 03:11 PM
How do I insert a new worksheet consecutively? lady-pearl Excel Discussion (Misc queries) 6 December 20th 05 04:47 PM
Consecutively Number Purchase Orders debcps Excel Worksheet Functions 1 May 18th 05 03:51 PM


All times are GMT +1. The time now is 03:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"