+ Reply to Thread
Results 1 to 2 of 2

Macro erases data inputted

Hybrid View

  1. #1
    Registered User
    Join Date
    09-23-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2010
    Posts
    2

    Macro erases data inputted

    Hi,

    I am hoping someone can help me with a quick fix. This macro takes data from one sheet and pastes it into another sheet. Columns B, C and D are all populated from another sheet. I need to enter data in columns E and F with the ability to run the macro and not lose the data inputted in E and F.

    To put it simply, I need this macro to run repeatedly without affecting columns E and F.

    Thank you in advance.


    Sub ZeroBasedRationale()
    
    Dim StartingCell As Range
    Dim StartingAccount As Range
    Dim StartingDesc As Range
    Dim StartingAmount As Range
    Dim n As Long
    Dim m As Long
    
    Sheets("Tab 7 Zero Based Rationale").Range("B10:D350").Delete
    
    Set StartingCell = Sheets("Tab 1 Summary").Range("N15")
    Set StartingAccount = Sheets("Tab 7 Zero Based Rationale").Range("B10")
    Set StartingDesc = Sheets("Tab 7 Zero Based Rationale").Range("C10")
    Set StartingAmount = Sheets("Tab 7 Zero Based Rationale").Range("D10")
    
    
    For i = 1 To 481
    
    If StartingCell.Offset(m, 0).Value <> 0 And StartingCell.Offset(m, -13).Value <> 0 And StartingCell.Offset(m, -12).Value <> 0 And StartingCell.Offset(m, 0).Value <> 0 Then
    
    StartingAccount.Offset(n, 0) = StartingCell.Offset(m, -13).Value
    StartingDesc.Offset(n, 0) = StartingCell.Offset(m, -12).Text
    StartingAmount.Offset(n, 0) = StartingCell.Offset(m, 0).Value
    
    n = n + 1
    m = m + 1
    
    Else
    
    m = m + 1
    
    
    End If
    
    Next i
    
    End Sub

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro erases data inputted

    I think this line:

    Sheets("Tab 7 Zero Based Rationale").Range("B10:D350").Delete
    is your problem.

    The delete method is the same as right clicking the cells and selecting delete, which then gives you the option to shift up/down/left/right. I think by default your code will chose to shift cells left, so columns E and F become columns A and B which are then overwritten in the rest of your code. Try using:
    Sheets("Tab 7 Zero Based Rationale").Range("B10:D350").ClearContents
    instead.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Problem with macro that resets and erases new data each time it is run.
    By SMcuthbert in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 08-19-2013, 02:27 PM
  2. [SOLVED] Need a Macro Function that erases dependent cells until dropdown box is selected!
    By voelkerl in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-11-2013, 08:20 AM
  3. Need Macro For Paste Special Value ONLY once a variable is inputted to a cell
    By jbench18 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-11-2013, 03:41 PM
  4. Refresh Data erases my rows!
    By paindivine in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 12-12-2006, 06:15 PM
  5. Replies: 3
    Last Post: 11-08-2005, 11:35 AM

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