+ Reply to Thread
Results 1 to 9 of 9

Macro to update cells based on a named range

  1. #1
    Registered User
    Join Date
    10-10-2012
    Location
    Reading, PA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Macro to update cells based on a named range

    I currently have a print macro that looks for blanks in column A hides them and prints(shown below). Now i want to add to this macro to have cell B4 update for everything in my named range (named range is List).

    If my named range consisted of 5 items (A,B,C,D,E) I want to macro to put "A" in B4 then print (I have formulas looking at cell B4). Then put "B" in cell B4, and print. And so on.

    Please Login or Register  to view this content.
    Thanks,
    Jeff
    Last edited by jeffreybrown; 10-10-2012 at 07:55 PM. Reason: Added code tags for new user. Please use code tags when posting code...Thanks.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Macro to update cells based on a named range

    Hi

    I'm assuming that you want the printout loop to happen after the row hiding so add something like
    Please Login or Register  to view this content.
    HTH

    rylo

  3. #3
    Registered User
    Join Date
    10-10-2012
    Location
    Reading, PA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro to update cells based on a named range

    Hi Rylo,

    I want it to loop after all the rows are unhidden. My marco hides anything in column A that is blank..prints then unhides all rows. The new piece i am looking for will update b4 with the numbers from my named range (my named range is in sheet 1 and b4 the cell that i want to update is in sheet 2 - b4 is also a data validation list) and re run my print macro. I want it to loop all the way through my named range.
    Last edited by bomex1018; 10-10-2012 at 09:14 PM.

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Macro to update cells based on a named range

    Hi

    Ok, so add that code block after you have unhidden the rows.

    rylo

  5. #5
    Registered User
    Join Date
    10-10-2012
    Location
    Reading, PA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro to update cells based on a named range

    I am now getting a run time error with the code below. It is kicking out at Range("B4").Value = ce.Value

    Sub Alloy()
    Application.Calculation = xlManual
    Application.ScreenUpdating = False
    Range("A:A").EntireRow.Hidden = False
    Dim currentRow As Object
    For i = 1 To 15 'Range("A:A").Rows.Count
    If (Range("A:A").Rows(i).Text = "") Then
    Range("A:A").Rows(i).EntireRow.Hidden = True

    End If
    Next i
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    Range("A:A").EntireRow.Hidden = False
    For Each ce In Range("List")
    Range("B4").Value = ce.Value
    ActiveSheet.Calculate
    ActiveWindow.SelectedSheets.PrintOut Copies:=1
    Next ce
    Application.ScreenUpdating = True


    Application.Calculation = xlAutomatic
    End Sub

  6. #6
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Macro to update cells based on a named range

    Hi

    What happens if you run
    Please Login or Register  to view this content.
    Does it give you the individual entries in the named range "List" or error. If it errors, then where is the named range?

    rylo

  7. #7
    Registered User
    Join Date
    10-10-2012
    Location
    Reading, PA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro to update cells based on a named range

    The other code works if i put my name range in sheet 2 ..but i need my name range in sheet 1..and i need the macro to run in sheet 2
    Last edited by bomex1018; 10-10-2012 at 09:58 PM.

  8. #8
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Macro to update cells based on a named range

    Hi

    Don't know if that is a 2010 thing. It works in 2007. Maybe try
    Please Login or Register  to view this content.
    and see if that works when in sheet2.

    rylo

  9. #9
    Registered User
    Join Date
    10-10-2012
    Location
    Reading, PA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro to update cells based on a named range

    Im actually using 2003 at home right now. I think your right it should recognize my name range from sheet1 in 2010. Ill let you know tomorrow (have 2010 at work)..thanks for your help i really appreciate it.

+ 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