Results 1 to 5 of 5

Changing range names using VBA

Threaded View

  1. #1
    Registered User
    Join Date
    05-04-2011
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2011 OSX Home, Excel 2010 Home, Excel 2002 SP3 Work
    Posts
    29

    Changing range names using VBA

    Hi,

    I created this vba code (from scratch, I'm very proud of it). The code is assigned to a text box and when it's clicked the macro starts running. It's a pretty basic copy/paste so far but I want to add a few lines that does the following after the marked line:

    I want the macro to do a cells(1,lastrow+1).select and change the range name to whatever is in cells(1,lastrow+1) and substitute any spaces " " with "_". Then I want it to select the entire columns(lastrow+1) and change the name to whatever is in cells(1,lastrow+1) and add a "Col" at the end of the name.

    This is probably very easy to code, but I can't figure it out.

    Sub LäggTillNyProdukt()
        Dim LastColumn As Integer
        Dim LastRow As Integer
        
        'Lägg till ny uppdateringsknapp
        Sheets("uppdatera").Select
        'Hittar sista raden och ger den ett nummer
        LastRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
        Rows(LastRow).Copy
        Rows(LastRow + 2).Select
        ActiveSheet.Paste
        Range("B3").Copy
        Cells(LastRow + 2, 1).Select
        ActiveSheet.Paste
             
        'Lägg till information för lista
        Range("B3").Copy
        Sheets("Lista").Select
        'Hittar sista raden och ger den ett nummer
        LastRow = Cells(Rows.Count, "A").End(xlUp).Row
        Cells(LastRow + 1, 1).Select
        ActiveSheet.Paste
        Cells(LastRow + 1, 1).Copy
        Cells(1, LastRow + 1).Select
        ActiveSheet.Paste
        
    'ADD NEW LINES HERE
    
        'Gå tillbaka till Uppdatering
        Sheets("Uppdatera").Select
        Range("B3").Select
        Application.CutCopyMode = False
           
    End Sub
    Last edited by Ranew; 05-31-2011 at 04:54 AM.

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