+ Reply to Thread
Results 1 to 5 of 5

How to go to the next sheet if there is no one

  1. #1
    Registered User
    Join Date
    09-17-2021
    Location
    Gdynia
    MS-Off Ver
    2016
    Posts
    66

    How to go to the next sheet if there is no one

    I'd like to write a loop or an If procedure that will go to the next sheet or continue the macro when it checks that there is no sheet. How best to do it

    Please Login or Register  to view this content.
    Similiar cross post : https://stackoverflow.com/questions/...09806_71114414
    Attached Files Attached Files

  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: How to go to the next sheet if there is no one

    Hi,

    It's not clear why you first copy F4 from the Tabela sheet (which doesn't actually contain a table and then paste to G17 on a sheet, then copy J5 and immediately paste that to the same G17 cell you've just updated, and then repeat the J5 copy paste G17 a second time.

    In general this is what I think you're trying to do. I can't be certain of which cells need pasting to so it uses your G17 and one I've assumed J17 - change that as necessary. You didn't say whether you are copying text or numeric values so I've Dim'd the vVal1 and vVal2 as Variants. If they're always the same text or number then Dim them appropriately, e.g. Dim st1 as String or Dim lVal1 as Long

    Incidentally it's always best to use theVBA Sheet Code name in code, NOT the tab name, so in your case instead of
    vVal1 = Sheets("Tabela_COREP").Range("F4").Value
    use
    vVal1 = Sheet3.Range("F4").Value


    Please Login or Register  to view this content.
    Last edited by Richard Buttrey; 02-15-2022 at 06:34 AM.
    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
    09-17-2021
    Location
    Gdynia
    MS-Off Ver
    2016
    Posts
    66

    Re: How to go to the next sheet if there is no one

    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    It's not clear why you first copy F4 from the Tabela sheet (which doesn't actually contain a table and then paste to G17 on a sheet, then copy J5 and immediately paste that to the same G17 cell you've just updated, and then repeat the J5 copy paste G17 a second time.

    In general this is what I think you're trying to do. I can't be certain of which cells need pasting to so it uses your G17 and one I've assumed J17 - change that as necessary. You didn't say whether you are copying text or numeric values so I've Dim'd the vVal1 and vVal2 as Variants. If they're always the same text or number then Dim them appropriately, e.g. Dim st1 as String or Dim lVal1 as Long

    Incidentally it's always best to use theVBA Sheet Code name in code, NOT the tab name, so in your case instead of
    vVal1 = Sheets("Tabela_COREP").Range("F4").Value
    use
    vVal1 = Sheet3.Range("F4").Value


    Please Login or Register  to view this content.
    I mean, I have multiple sheets in the template, Eg C_0700_002 then C_0700_0007 and so on. I mean, if it doesn't find this sheet, the macro will continue to work. And it went on to the next part of the macro.

  4. #4
    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: How to go to the next sheet if there is no one

    Yes I understand what you are trying to do but your original explanation didn't line up with your code.

    The question is does my code help you?
    Your cell references weren't consist but the code shows you how cycle through all sheets with one exception (the Tabela sheet) and copy F4 & J5 pasting them to G17 & J17 on each sheet. Change the refs as necessary.

    Incidentally there's no need to include all the text of the post to which you are replying. Only use quoted parts where it's necessary to aid understanding. Otherwise it causes unnecessary clutter.

  5. #5
    Registered User
    Join Date
    09-17-2021
    Location
    Gdynia
    MS-Off Ver
    2016
    Posts
    66

    Re: How to go to the next sheet if there is no one

    Ok, I'm sorry, so my code should look like I should pass between Sheets ? What i do wrong still ?
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Google Sheet : Time Stamp Code Work Only in Active Sheet Always Rename Sheet
    By Jhon Mustofa in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 2
    Last Post: 11-23-2021, 10:18 AM
  2. Replies: 5
    Last Post: 05-21-2021, 11:23 AM
  3. Lookup Value from Sheet 4 in Sheet 2, if found copy Sheet 2 Active Row to Sheet 5
    By lgosso23 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-11-2013, 02:51 PM
  4. [SOLVED] Match Value in Sheet 1 with Sheet 2, copy entire row from sheet 1 to new sheet
    By lzyshaman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-01-2013, 07:48 AM
  5. [SOLVED] find code# from sheet 1 on sheet 2, compare value on sheet 1 with value on sheet 2
    By BlakeLee in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-27-2013, 01:52 PM
  6. Replies: 11
    Last Post: 10-14-2012, 01:03 PM
  7. Replies: 2
    Last Post: 10-12-2010, 05:00 PM

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