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!
Hi bell123
This code is included in the attached and appears to do as you require.
Let me know of issues.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
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks