+ Reply to Thread
Results 1 to 10 of 10

Macro eliminates row and fix alignment

  1. #1
    Registered User
    Join Date
    10-06-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    37

    Macro eliminates row and fix alignment

    Hi

    I have a database that receives data and nobody can change. To delete the data I use a macro where I write the number of the column ID and it deletes the row (can see the code below). And what I want it's when a row is removed, the ID numbers automatically readjust to always stay with the sequence 1,2,3,4,5,6,7,8... You can see this xlsx: lmb.xlsx Does anyone know how to do?

    Private Sub CommandButton1_Click()


    ThisWorkbook.Worksheets("Plan1").Activate


    Range("B7").Select
    While ActiveCell <> ""
    If TextBox1.Text = ActiveCell Then
    While ActiveCell = TextBox1.Text
    ActiveCell.EntireRow.Delete


    Wend
    End If
    ActiveCell.Offset(1, 0).Activate
    Wend


    End Sub
    Cheers!

    :pray:

  2. #2
    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,197

    Re: Macro eliminates row and fix alignment

    Hi, carapins,

    maybe have a thought about entering a formula into B7
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    and drag down.

    I doubt this to be a good idea - an ID should stay the same throughout and should not be altered if any ID is deleted or amended (at least thatīs what it means in a RDBM).

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    01-26-2012
    Location
    Slovenia; Kranj
    MS-Off Ver
    Office 365
    Posts
    67

    Re: Macro eliminates row and fix alignment

    Hi,

    can you put formula in ID column? If yes, than put this formula in B7 (example for your attached file) ... =ROW()-6 ... and then copy formula down. So if row will be deleted, the sequence remain same ...

    Or do you want to have macro solution?


    This is fast solution ... cheers, Marko
    IF a = b THEN
    GO "back to school"

  4. #4
    Registered User
    Join Date
    10-06-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: Macro eliminates row and fix alignment

    Thanks guys for feedback! That function works but for what I want it doesnt, because when its added more data it will need to add this function to the new ID number. What I want is that no one can move data or change something (the cells will be blocked) and so cant go there to add this function. It has to be automatic...

  5. #5
    Registered User
    Join Date
    01-26-2012
    Location
    Slovenia; Kranj
    MS-Off Ver
    Office 365
    Posts
    67

    Re: Macro eliminates row and fix alignment

    And how you'll be adding more data? Via macro? If yes, than just add a line in that macro ...

    Please Login or Register  to view this content.
    ... with changing "activecell" and "-6" based on your "appending macro".

    Cheers, Marko

  6. #6
    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,197

    Re: Macro eliminates row and fix alignment

    Hi, carapins,

    (the cells will be blocked)
    If that means the sheet is protected you would either need to unprotect the sheet, run the code, protect at the end of the macro or set the volatile setting of protecting the sheet using UserInterfacecOnly:=True which would block normal actions but allow macros to be run.

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    This formula will check if an entry is being made to column C and then display the value else remain empty. This formula could be dragged down as far as you want.

    Please Login or Register  to view this content.
    Still I donīt think that manipulating the IDs is the way to go.

    Ciao,
    Holger

  7. #7
    Registered User
    Join Date
    10-06-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: Macro eliminates row and fix alignment

    Hi, carapins,


    If that means the sheet is protected you would either need to unprotect the sheet, run the code, protect at the end of the macro or set the volatile setting of protecting the sheet using UserInterfacecOnly:=True which would block normal actions but allow macros to be run.
    Thanks for advice but where I put that code (UserInterfacecOnly:=True)? In a private_sub of worksheet or all of the macro I created?


    Formula: copy to clipboard
    Please Login or Register  to view this content.

    This formula will check if an entry is being made to column C and then display the value else remain empty. This formula could be dragged down as far as you want.
    I don't know where I should put that function... In B7 doesnt work...

    Please Login or Register  to view this content.
    Still I donīt think that manipulating the IDs is the way to go.

    Ciao,
    Holger
    Wow that code works fine! But ok I'll do it by function, but i don't know how to apply the function...

  8. #8
    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,197

    Re: Macro eliminates row and fix alignment

    Hi, carapins,

    the command is volatile and must be set on any opening or activating the worksheet as it will not be saved with the workbook. So it could be either Workbook_Open in ThisWorkbook or behind the sheet in a Worksheet_Activate.

    Sorry about the formula - it should be checking the cell from the very same row. So it must be C7 instead of C6.

    I'll do it by function, but i don't know how to apply the function
    Sorry but I donīt understand what you mean by that.

    Ciao,
    Holger

  9. #9
    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,197

    Re: Macro eliminates row and fix alignment

    Hi, carapins,

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

    http://www.vbaexpress.com/forum/show...-fix-alignment

    Ciao,
    Holger

  10. #10
    Registered User
    Join Date
    10-06-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: Macro eliminates row and fix alignment

    I've already got used that function. Thanks

    Ok, I didnt know that rule. Sorry

    Btw, thanks for feedback!
    Last edited by carapins; 10-17-2013 at 10:51 AM.

+ 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. Macro for alignment
    By kinokino in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-09-2013, 12:25 AM
  2. Text alignment in a range of cells using macro .
    By amlan009 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-30-2012, 12:49 AM
  3. Macro to change axis alignment
    By jwskibum in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 05-17-2008, 07:40 AM
  4. IF function that eliminates empty rows
    By abrazee in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-03-2006, 12:29 AM
  5. [SOLVED] My Excel drop-down list eliminates from list options chosen. Help
    By Sybil in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-19-2006, 05:25 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