+ Reply to Thread
Results 1 to 16 of 16

Help needed in macro/VBA selection and formatting

  1. #1
    Registered User
    Join Date
    08-22-2012
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2007
    Posts
    8

    Help needed in macro/VBA selection and formatting

    Hi guys,

    I'm a complete excel/VBA laymen so bear with me as I try to explain my problem as best as I can. I have tried to automate a weekly report using macros/VBA and it used to work fine till now. The code (which i will paste below) is supposed to search from column J1 till that column becomes empty and delete everything that isn't the following three statements:

    - Backup Completed
    - Backup Completed with warnings
    - Exit Status

    This used to work fine but now my macro just ends up deleting everything :'(. Please help me...

    Code:

    Please Login or Register  to view this content.
    Last edited by arlu1201; 08-22-2012 at 06:01 AM.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Help needed in macro/VBA selection and formatting

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    08-22-2012
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Help needed in macro/VBA selection and formatting

    Hi Bob,

    Thanks a lot for your code! But ummmm I hit a snag. When I ran the code it gave me an error at the 'lastrow = .Range(("J1").End(xlDown).Row
    statement. The error was runtime error 424, 'object required' :S

    Cheers,
    Hassan

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Help needed in macro/VBA selection and formatting

    Welcome to the forum, Hassanq23,

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature.

    ---------- Post added at 03:32 PM ---------- Previous post was at 03:31 PM ----------

    Change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    This will give you the correct count. If you use end(xldown) it will stop if it encounters a blank cell.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  5. #5
    Registered User
    Join Date
    08-22-2012
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Help needed in macro/VBA selection and formatting

    Hi,

    I got the same error again after i replaced it with the following code:

    Please Login or Register  to view this content.
    hmmmm Will it help if i attach the excel file that I am using with this post as well?

    Cheers,
    Hassan

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Help needed in macro/VBA selection and formatting

    You have double (( there.

    Change it to
    Please Login or Register  to view this content.

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Help needed in macro/VBA selection and formatting

    Hi, hassanq23,

    change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Worked for me with Excel2007.

    Ciao,
    Holger

  8. #8
    Registered User
    Join Date
    08-22-2012
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Help needed in macro/VBA selection and formatting

    Hi guys,

    Made the changes as Arlette recommended and still got the same error. Then made the changes that Holger said and now get the following error:

    Please Login or Register  to view this content.
    Cheers,
    HQ

  9. #9
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Help needed in macro/VBA selection and formatting

    On which line?

  10. #10
    Registered User
    Join Date
    08-22-2012
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Help needed in macro/VBA selection and formatting

    Hi,

    The same line i.e.

    Please Login or Register  to view this content.
    Cheers,
    HQ

  11. #11
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Help needed in macro/VBA selection and formatting

    It should be
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    08-22-2012
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Help needed in macro/VBA selection and formatting

    Ok progress! its not giving me an error anymore but hmmm its not working as well. I used the debug 'step into' option on excel and saw that the code will go till the first for loop and then instead of moving on to the underlying If condition it makes a jump to the 2nd for loop and well sort of does nothing .

    cheers,
    Hassan

  13. #13
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Help needed in macro/VBA selection and formatting

    Where are all the double opening brackets coming from? Twice you have reproduced code that had a single bracket originally that ended up with doubles.

  14. #14
    Registered User
    Join Date
    08-22-2012
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Help needed in macro/VBA selection and formatting

    Hi Bob,

    Ya I saw that and removed the double brackets. And now the final code looks as below, still not working properly though :

    Please Login or Register  to view this content.
    Cheers,
    HQ

  15. #15
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Help needed in macro/VBA selection and formatting

    Can you tell us what is happening that shouldn't/not happening that should?

  16. #16
    Registered User
    Join Date
    08-22-2012
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Help needed in macro/VBA selection and formatting

    Hi,

    Wonder if my last post went through, anyways I am trying to find out why this part of my script doesnt work. Its supposed to select the active cell in Coulmn 'J' and then skip the deleting of an entire row if the cell contains one of the three phrases below:
    -Backup Completed
    -Backup Completed with warnings
    -Exit Status

    The code is as follows:
    Please Login or Register  to view this content.
    Problem is that even if it detects one of the three phrases it still goes on and deletes the whole line. I'm sure I am making some incredibly stupid mistake here but please help me out.

    cheers,
    HQ

+ 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