+ Reply to Thread
Results 1 to 9 of 9

Thread: Macro to Delete Row and Update Cell Value

  1. #1
    Registered User
    Join Date
    01-25-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    6

    Macro to Delete Row and Update Cell Value

    Hello,
    Are you able to help me with a Macro?
    I tried recording but I find it too long and messy, perhaps you can help with a more simple VBA?
    Basically, what I wanted is to have a button that will delete the row from Row 1 to Row 22.
    After that, I would like to replace the value of AA1 to AR1, the value needs to be "1".
    I hope you will be able to help. Thank you in advance.

    I have attached a test document. Thanks again.

    Cheers,
    John
    Attached Files Attached Files
    Last edited by DapprD0n; 01-26-2012 at 02:08 AM.

  2. #2
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    369

    Re: Macro to Delete Row and Update Cell Value

    I'm a bit confused by the 2nd part of your request. You would like the value of AA1 to be set equal to whatever is in AR1, but that value needs to be 1? The value in both cells of the attached test.xls workbook is the string AAAA.

    You would need to tie the following to an ActiveX command button or Form Control.

    Sub DeleteAndChange()
    '/======================================
    '/ Tie to CommandButton_1; Sheet 1 or Form Control
    '/ Will delete rows 1:22; AA1 to AR1
    '/======================================
    Sheets("Sheet1").Range("1:22").EntireRow.Delete
    
    Range("AA1") = Range("AR1")
    
    End Sub

  3. #3
    Registered User
    Join Date
    01-25-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Macro to Delete Row and Update Cell Value

    Hi AlvaroSiza,
    Thanks for the help.
    The 2nd part, I would like the value on those cells to be changed to 1, replacing whatever it is in there.
    Is that possible?
    I will try the delete code and report back shortly. Thanks again.

  4. #4
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    369

    Re: Macro to Delete Row and Update Cell Value

    Revise previous to the following.

    Quote Originally Posted by AlvaroSiza View Post
    Sub DeleteAndChange()
    '/======================================
    '/ Tie to CommandButton_1; Sheet 1 or Form Control
    '/ Will delete rows 1:22; AA1 to AR1
    '/======================================
    Sheets("Sheet1").Range("1:22").EntireRow.Delete
    
    Range("AA1") = 1
    Range("AR1") = 1
    
    End Sub

  5. #5
    Registered User
    Join Date
    01-25-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Macro to Delete Row and Update Cell Value

    Tried it! It's working except for the part where it changes the value to 1. It only replaces AA1 and AR1 instead of AA1 to AR1.
    Do I need to code it individually? AB1=1, AC1=1 etc?

    Thanks again sir!

  6. #6
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    369

    Re: Macro to Delete Row and Update Cell Value

    Oh...I see now. Hang on.

  7. #7
    Registered User
    Join Date
    01-25-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Macro to Delete Row and Update Cell Value

    Okay sir =)

  8. #8
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    369

    Re: Macro to Delete Row and Update Cell Value

    Sub DeleteAndUpdate()
    '/======================================
    '/        Function(s):
    '/             - Deletes rows 1 to 22
    '/             - Sets values of AA1:AR1 = 1
    '/======================================
    Application.ScreenUpdating = False
         Sheets("Sheet1").Range("1:22").EntireRow.Delete
         Range("AA1:AR1") = 1
    Application.ScreenUpdating = True
    End Sub

  9. #9
    Registered User
    Join Date
    01-25-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Macro to Delete Row and Update Cell Value

    Wonderful! Thank you very much sir!
    Just what I wanted. =)

+ 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.2.0