Solved

Saving form data to worksheet goes in row ABOVE

Posted on 2011-03-03
6
287 Views
Last Modified: 2012-05-11
I have a user form that accepts changes.  When the user hits save, the data should be saved in the row that appears on the form via the VBA code.  Say data is sourced in Row 11 and this row number is what is reflected on the form.  When the user saves changes, all the data should go back to the proper field on the form in Row 11, but it goes into row 10!  I checked and it seems c onsistent, the data is saved in the row above the row reflected on the form.  
Private Sub SaveData()
'Save changed data to Settings worksheet
With ThisWorkbook.Worksheets("Settings")
    .Unprotect Password:=s_PSWD
          With .Rows(Me.txtRowNumber)
                .Cells(0, 1).Value = Me.txtAddedBy.Value
                .Cells(0, 2).Value = Me.txtAddDate.Value
                .Cells(0, 3).Value = "Yes"
                .Cells(0, 4).Value = Me.txtClosedChangedBy.Value
                .Cells(0, 5).Value = Me.txtCloseChangeDate.Value
                .Cells(0, 6).Value = Me.txtPortfolioCode.Value
                .Cells(0, 7).Value = Me.txtPortfolioName.Value
                .Cells(0, 8).Value = Me.txtURLSectorSummary.Value
                .Cells(0, 9).Value = Me.txtURLSectorDetail.Value
                .Cells(0, 10).Value = Me.txtURLRatingSummary.Value
                .Cells(0, 11).Value = Me.txtURLRatingDetail.Value
         End With
    .Protect Password:=s_PSWD
End With
'Reset form for next data set changes
Call ClearControls
MsgBox "Data has been saved", vbOKOnly
        
Exit_ErrorHandler:
    Exit Sub
ErrorHandler:
        MsgBox Err.Number & " Description: " & Err.Description
        Resume Exit_ErrorHandler
End Sub

Open in new window

0
Comment
Question by:ssmith94015
  • 2
  • 2
  • 2
6 Comments
 
LVL 24

Expert Comment

by:StephenJR
ID: 35028791
Might be your cells notation. Does this work?

.Cells(1, 1).Value = Me.txtAddedBy.Value
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 35028796
Change the zeroes in .Cells(0, 1) etc to 1 and you should be fine.
0
 

Author Comment

by:ssmith94015
ID: 35028837
I am looking at it and maybe it is simply that I am referring to the row number, but not telling it to start with cell A11?  that is, if the .Rows(Me.txtRowNumber) = 11, I think I am missing the point in that I need to now tell it the starting cell is A11?  You both are correct in that Cells(1,1) will work, but I am wondering that myproblem is I simply am not telling it which cell to actually start with?
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 24

Assisted Solution

by:StephenJR
StephenJR earned 250 total points
ID: 35028858
If txtRowNumber=11 then Rows(11).Cells(1,1) is A11.
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 250 total points
ID: 35028867
No, you are telling it the correct start cell, but Cells(0,1) is the cell above that cell. Perhaps you are confusing it with .Offset(0,1) which would be the cell in the same row but one column across?
0
 

Author Closing Comment

by:ssmith94015
ID: 35028897
Rorya, yes, I think I am getting confused.  I was assuming zero-based starting point and now this does make sense.  Thank you both!  Am splitting points as you both answered the question.  And I appreciate the lesson.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now