Consulting

Results 1 to 8 of 8

Thread: Solved: Cell address : loop till 2006 data

  1. #1

    Solved: Cell address : loop till 2006 data

    hello


    1)
    i have a date column which is Cell A


    the Range has dates from 2005 till update

    is that possible to loop only 2007 values?

    & to know the cell adress where it end?


    2) how to find specific value cell

    i.e,


    2) if i have 200 rows & i just want to get the cell where value = "ABC"

    thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by skaswani
    1) i have a date column which is Cell A, the Range has dates from 2005 till update is that possible to loop only 2007 values & to know the cell adress where it end?
    [vba]
    With Activesheet
    For i = 1 To .Cells(.Rows.Count,"A").End(xlUp).Row
    If Year(.Cells(i,"A").VAlue) = 2007 Then Msgbox .Cells(i,"A").Address
    Next i
    [/vba]

    Quote Originally Posted by skaswani
    2) how to find specific value cell

    i.e, if i have 200 rows & i just want to get the cell where value = "ABC"
    [vba]

    Dim cell As Range

    With ActiveSheet
    Set cell = .Columns(1).Find("ABC")
    If Not cell Is Nothing Then
    MsgBox cell.Address
    End If
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    To get the range.
    [VBA]Option Explicit

    Sub MatchDate()
    'http://support.microsoft.com/default.aspx?scid=kb;en-us;213643
    Dim Yr As String
    Dim Rng As Range, Source As Range, Strt As Long, Endd As Long

    'Set Year and Range
    Yr = Format(InputBox("Enter year yy"), "00")
    Set Source = Range("A:A")

    Strt = DateRow("1/1/" & Yr, Source, 0)
    If Strt = 0 Then Strt = DateRow("1/1/" & Yr, Source, 1) + 1
    Endd = DateRow("31/12/" & Yr, Source, 1)
    Set Rng = Range(Cells(Strt, 1), Cells(Endd, 1))

    Rng.Interior.ColorIndex = 6

    End Sub

    Function DateRow(Dte As String, Rng As Range, Mtch As Long) As Long
    On Error Resume Next
    DateRow = Application.Match(CLng(CDate(Dte)), Rng, Mtch)
    End Function

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Dear mdmackillop

    wheen i execute ur cute it gives me this error!
    [vba]
    application defined or object defined error
    [/vba]

    Dear Xld

    you code help me alot, but i have just one problem..

    u have used the FOR LOOP, so it gives me message after every line, actuly what i have to do is that i have to get the last cell no#



    my data looks like this


    11-Jan-07 69
    10-Jan-07 69.2
    9-Jan-07 69.95
    8-Jan-07 69
    5-Jan-07 69.45
    4-Jan-07 69.25
    29-Dec-06 68.5
    28-Dec-06 69
    27-Dec-06 68.5



    so when it loop in For, after every row it gives me MsgBox with cell addy

    actully i dont know how to use While Unil loop

    thanks

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Can you post your data in a workbook. Use Manage Attachments in the Go Advanced section
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by skaswani
    Dear Xld

    you code help me alot, but i have just one problem..

    u have used the FOR LOOP, so it gives me message after every line, actuly what i have to do is that i have to get the last cell no#

    my data looks like this

    11-Jan-07 69
    10-Jan-07 69.2
    9-Jan-07 69.95
    8-Jan-07 69
    5-Jan-07 69.45
    4-Jan-07 69.25
    29-Dec-06 68.5
    28-Dec-06 69
    27-Dec-06 68.5


    so when it loop in For, after every row it gives me MsgBox with cell addy

    actully i dont know how to use While Unil loop
    [vba]


    With Activesheet
    For i = .Cells(.Rows.Count,"A").End(xlUp).Row To 1 Step -1
    If Year(.Cells(i,"A").VAlue) = 2007 Then
    Msgbox .Cells(i,"A").Address
    Exit For
    End If
    Next i
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    "Provide sample data and layout if you want a quicker solution." - MD
    Data in ascending/descending order can affect solutions, hence my request in post #5
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    u guys really dam good

    God Bless u

    regards,

Posting Permissions

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