+ Reply to Thread
Results 1 to 2 of 2

Thread: Macro for saving / loading values between sheets

  1. #1
    Registered User
    Join Date
    02-11-2011
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2003
    Posts
    13

    Macro for saving / loading values between sheets

    Hello all,

    I've been trying to write a macro for taking values that are entered on one worksheet and saving them on anothe worksheet; where they are saved is based on a value that is entered on the first sheet.

    In the example provided, and on the "Today's Values" worksheet, I have fields for values 1 - 15. Only green fields require an entry by the user. In the "Today Is" field, there is a data validated list. This list validates to the values of the top row on the "Weekly Log" worksheet. So depending on the "Today Is" field, I need the macro to take the values and put them in the corresponding value fields on the "Weekly Log" worksheet. This would be the effect of the "Save" macro button.

    Also, I'd like to make it so that I can recall values that are already entered. This would be based on the "Today Is" field, where upon hitting the "Load" macro button, the values for that given day that are currently in the "Weekly Log" sheet will repopulate on the "Today's Values" sheet.

    Can anyone provide some insight and help? Thanks!
    Attached Files Attached Files

  2. #2
    Forum Guru jaslake's Avatar
    Join Date
    02-21-2009
    Location
    mineral city, ohio
    MS-Off Ver
    Excel 2007; Excel 2000
    Posts
    4,004

    Re: Macro for saving / loading values between sheets

    Hi bell123

    This code is included in the attached and appears to do as you require.
    Option Explicit
    Sub Find_Stuff()
        Dim FindString As String
        Dim Rng As Range
        Dim rCount As Long
        Application.ScreenUpdating = False
        rCount = Application.CountA(Range("B:B"))
        FindString = Range("B1").Value
        If rCount > 1 Then
            If Trim(FindString) <> "" Then
                With Sheets("Weekly Log").Range("B1:F1")
                    Set Rng = .Find(What:=FindString, _
                            After:=.Cells(.Cells.Count), _
                            LookIn:=xlValues, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, _
                            MatchCase:=False)
                    If Not Rng Is Nothing Then
                        Range(Range("B1").Offset(1, 0), Range("B" & Rows.Count).End(xlUp)).Copy
                        Rng.Offset(1, 0).PasteSpecial
                    Else
                        MsgBox "Nothing found for " & FindString
                    End If
                End With
            End If
        Else
            MsgBox "No Data To Save For " & FindString
        End If
        Application.CutCopyMode = False
        Application.ScreenUpdating = True
    End Sub
     
     
    Sub Find_Stuff_Redux()
        Dim FindString As String
        Dim Rng As Range
        Dim rCount As Long
        Application.ScreenUpdating = False
        FindString = Range("B1").Value
        Range("B2", Range("B2").End(xlDown)).ClearContents
        If Trim(FindString) <> "" Then
            With Sheets("Weekly Log").Range("B1:F1")
                Set Rng = .Find(What:=FindString, _
                        After:=.Cells(.Cells.Count), _
                        LookIn:=xlValues, _
                        LookAt:=xlWhole, _
                        SearchOrder:=xlByRows, _
                        SearchDirection:=xlNext, _
                        MatchCase:=False)
                If Not Rng Is Nothing Then
                    rCount = Application.CountA(Sheets("Weekly Log").Columns(Rng.Column))
                    If rCount > 1 Then
                        Sheets("Weekly Log").Range(Rng.Offset(1, 0).Address, Sheets("Weekly Log").Range(ColumnLetter(Rng.Column) & Rows.Count).End(xlUp)).Copy
                        Sheets("Todays Values").Range("B1").Offset(1, 0).PasteSpecial
                    Else
                        MsgBox "Nothing Data To Load For " & FindString
                    End If
                End If
            End With
        End If
        Application.CutCopyMode = False
        Application.ScreenUpdating = True
    End Sub
     
     
    Function ColumnLetter(ColumnNumber As Long) As String
    ' From http://www.craigmurphy.com/blog/?p=150
    ' Works in Excel 2007
        Dim ColNum As Integer
        Dim ColLetters As String
        ColNum = ColumnNumber
        ColLetters = ""
        Do
            ColLetters = Chr(((ColNum - 1) Mod 26) + 65) & ColLetters
            ColNum = Int((ColNum - ((ColNum - 1) Mod 26)) / 26)
        Loop While ColNum > 0
        ColumnLetter = ColLetters
    End Function
    Let me know of issues.
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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