+ Reply to Thread
Results 1 to 6 of 6

brows trough line and columns

  1. #1
    Registered User
    Join Date
    04-01-2013
    Location
    oslo
    MS-Off Ver
    Excel 2007
    Posts
    3

    brows trough line and columns

    Hello

    Here is what my program is supposed to do

    STEP1: go trough [A1:B3] in the "sheet1" (see below):

    Example of Sheet 1:
    - A B
    1 2 3
    2 3 0
    3 0 5

    If he finds a value equal to 0 he will copy it and paste it in the same cell but in (sheet2):

    Result in Sheet 2:
    - A B
    1 - -
    2 - 0
    3 0 -

    My problem is that I don t know how to tell my program to go trough all the lines and columns

    So far I only do the colums hehe

    Set Info = Sheets("Sheet1").Range("A1:B3")
    Set Result = Sheets("Sheet2").Range("A1:B3")


    For i = 1 To Info.Count

    If Info.Cells(i, 1) = "0" Then
    Info.Cells(i, 1).Copy
    Result.Cells(i, 1).PasteSpecial xlPasteValues
    End If
    Next i

    If you have any advice

    Thank you very much
    Last edited by vbdisdoc; 04-01-2013 at 11:50 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: brows trough line and columns

    Hi,

    Why bother with a macro when in sheet 2 A1 you could just enter

    =IF(Sheet1!A1=0,0,"-")

    then copy this across and down as far as necessary.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    04-01-2013
    Location
    oslo
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: brows trough line and columns

    Hello Richard,
    Thank you for your reply. Well it is because I don't want to display formulas in the cells.

    And I try to make my question as simple as possible to get a clear answer (asking a good questions is sometimes the hardest)

    But I guess the real reason is that I am very curious of how to do it.

    So I'll be verry happy if I could find the answer.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,355

    Re: brows trough line and columns

    Hi vbdisdoc and welcome to the forum. Try this code below.
    Please Login or Register  to view this content.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: brows trough line and columns

    Hi,

    I'd still be inclined to do it in the same way. So with a macro and to avoid a loop which can be time consuming

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    04-01-2013
    Location
    oslo
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: brows trough line and columns

    Hi Marvin and Richard,

    Thank you very much for your help
    Hope I can also help newbees (like myself) in the futur.

    All the best

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1