Results 1 to 10 of 10

Thread: Numbered column in vba

  1. #1
    Senior Member
    Join Date
    Oct 2011
    Posts
    135
    Rep Power
    14
    Last edited by DocAElstein; 04-16-2024 at 12:58 PM.

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    You could try this formula.

    =COUNTIF($A$1:$A$9,A1)-COUNTIF($A$1:A1,A1)+1

    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://eileenslounge.com/viewtopic.php?p=316254#p316254
    https://eileenslounge.com/viewtopic.php?p=316280#p316280
    https://eileenslounge.com/viewtopic.php?p=315915#p315915
    https://eileenslounge.com/viewtopic.php?p=315512#p315512
    https://eileenslounge.com/viewtopic.php?p=315744#p315744
    https://www.eileenslounge.com/viewtopic.php?p=315512#p315512
    https://eileenslounge.com/viewtopic.php?p=315680#p315680
    https://eileenslounge.com/viewtopic.php?p=315743#p315743
    https://www.eileenslounge.com/viewtopic.php?p=315326#p315326
    https://www.eileenslounge.com/viewtopic.php?f=30&t=40752
    https://eileenslounge.com/viewtopic.php?p=314950#p314950
    https://www.eileenslounge.com/viewtopic.php?p=314940#p314940
    https://www.eileenslounge.com/viewtopic.php?p=314926#p314926
    https://www.eileenslounge.com/viewtopic.php?p=314920#p314920
    https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=314837#p314837
    https://www.eileenslounge.com/viewtopic.php?f=21&t=40701&p=314836#p314836
    https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314621#p314621
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA

    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://eileenslounge.com/viewtopic.php?p=317218#p317218
    https://eileenslounge.com/viewtopic.php?p=316955#p316955
    https://eileenslounge.com/viewtopic.php?p=316955#p316955
    https://eileenslounge.com/viewtopic.php?p=316940#p316940
    https://eileenslounge.com/viewtopic.php?p=316927#p316927
    https://eileenslounge.com/viewtopic.php?p=317014#p317014
    https://eileenslounge.com/viewtopic.php?p=317006#p317006
    https://eileenslounge.com/viewtopic.php?p=316935#p316935
    https://eileenslounge.com/viewtopic.php?p=316875#p316875
    https://eileenslounge.com/viewtopic.php?p=316254#p316254
    https://eileenslounge.com/viewtopic.php?p=316280#p316280
    https://eileenslounge.com/viewtopic.php?p=315915#p315915
    https://eileenslounge.com/viewtopic.php?p=315512#p315512
    https://eileenslounge.com/viewtopic.php?p=315744#p315744
    https://www.eileenslounge.com/viewtopic.php?p=315512#p315512
    https://eileenslounge.com/viewtopic.php?p=315680#p315680
    https://eileenslounge.com/viewtopic.php?p=315743#p315743
    https://www.eileenslounge.com/viewtopic.php?p=315326#p315326
    https://www.eileenslounge.com/viewtopic.php?f=30&t=40752
    https://eileenslounge.com/viewtopic.php?p=314950#p314950
    https://www.eileenslounge.com/viewtopic.php?p=314940#p314940
    https://www.eileenslounge.com/viewtopic.php?p=314926#p314926
    https://www.eileenslounge.com/viewtopic.php?p=314920#p314920
    https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=314837#p314837
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 05-20-2024 at 04:05 PM.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #3
    Senior Member
    Join Date
    Oct 2011
    Posts
    135
    Rep Power
    14
    Hi,

    I messed around a bit 'to run in a loop vba.
    I wonder if you can better manage this cycle with an array

    Code:
    Option Explicit
    Public Const RigaUp = 2
    
    Sub a()
        Dim RigaDn As Long
        Dim Giorni As Variant
        Dim ciclo As Long
        Dim ciclo1 As Long
        Dim start As Integer
        Dim Old As Integer
        RigaDn = Cells(Rows.Count, 1).End(xlUp).Row
        Giorni = Range(Cells(RigaUp, 4), Cells(RigaDn, 5)).Value
        For ciclo = 1 To UBound(Giorni)
            Giorni(ciclo, 1) = Int(Giorni(ciclo, 1))
        Next
        Range("AA2:AA21") = Giorni
        For ciclo1 = 1 To UBound(Giorni)
            Cells(ciclo1 + 1, 28) = Contig(Range("AA" & ciclo1 + 1 & ":AA22"), Int(Giorni(ciclo1, 1)))
        Next
    End Sub
    Code:
    Function Contig(ByRef Myaddr As Range, ByVal myVal As String) As Integer
    For Each cell In Myaddr
        If cell.Value = myVal Then
            ccnt = ccnt + 1
        Else
            If ccnt > Contig Then Contig = ccnt
            ccnt = 0
        End If
    Next cell
    End Function
    Last edited by PcMax; 07-01-2012 at 09:12 PM. Reason: Code Function Contig:

  4. #4
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    14
    Quote Originally Posted by Admin View Post
    Hi

    You could try this formula.

    =COUNTIF($A$1:$A$9,A1)-COUNTIF($A$1:A1,A1)+1
    Another formula that can be used is this one...

    =COUNTIF(A1:A$9,A1)

    Change both A1 references to the cell reference for the cell that your data actually starts at.
    Last edited by Rick Rothstein; 07-02-2012 at 12:19 AM.

  5. #5
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    14
    Quote Originally Posted by PcMax View Post
    I messed around a bit 'to run in a loop vba.
    If you really need to do this in VBA (instead of using one of the formulas Admin or I posted earlier), then you can use this macro...

    Code:
    Sub CountDupesBackwards()
      Dim LastRow As Long
      Const DataColumn As String = "A"
      Const OutputColumn As String = "B"
      Const StartRow As Long = 2
      LastRow = Cells(Rows.Count, DataColumn).End(xlUp).Row
      With Cells(StartRow, OutputColumn).Resize(LastRow - StartRow + 1)
        .Formula = "=COUNTIF(" & DataColumn & StartRow & ":" & DataColumn & _
                   "$" & LastRow & "," & DataColumn & StartRow & ")"
        .Value = .Value
      End With
    End Sub
    Last edited by Rick Rothstein; 07-02-2012 at 12:19 AM.

  6. #6
    Senior Member
    Join Date
    Jun 2012
    Posts
    337
    Rep Power
    13
    You could use:

    Code:
    Sub snb()
      sn = Columns(1).SpecialCells(2)
        
      For j = 1 To UBound(sn)
        sn(j, 1) = UBound(Filter(Application.Transpose(sn), sn(j, 1))) + 1
      Next
        
      Columns(1).SpecialCells(2).Offset(, 3) = sn
    End Sub

  7. #7
    Senior Member
    Join Date
    Oct 2011
    Posts
    135
    Rep Power
    14
    Hi,

    I have tried and tested various suggestions recommended.
    Code Working successfully Thank Snb

  8. #8
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    14
    Quote Originally Posted by PcMax View Post
    I have tried and tested various suggestions recommended.
    Code Working successfully Thank Snb
    One caution with snb's code... it will work fine as long as all the values in your list are the same length (as you showed in your posting). However, if the length of the list items can vary, and more importantly, if a smaller value can be found as part of a larger value (for example, if your list could have both 1850 and 41850 in it), then snb's code will return incorrect answers.

  9. #9

  10. #10
    Senior Member
    Join Date
    Oct 2011
    Posts
    135
    Rep Power
    14
    Hi,

    My research uses the data in a column that I find in columns and refer to a date for equity securities.
    If all the data page are ordered and am in uniform, I should not have the problem reported.
    If the dates were not in order, however, would get positioning errors of the formulas.
    I could use an initial course to test the correctness of the data before running the code.

Similar Threads

  1. Replies: 10
    Last Post: 05-23-2013, 12:30 PM
  2. Replies: 6
    Last Post: 05-16-2013, 09:56 AM
  3. Numbered List Of Unique Values
    By xander1981 in forum Excel Help
    Replies: 6
    Last Post: 01-21-2013, 06:10 PM
  4. MS-Access Set Default Value of Column Using VBA
    By LalitPandey87 in forum Access Help
    Replies: 2
    Last Post: 04-08-2012, 09:40 AM
  5. Splittting Data Into Different Worksheets Column Wise In VBA
    By rajeshd@live.in in forum Excel Help
    Replies: 1
    Last Post: 01-21-2012, 04:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •