Solved

Tweak Existing VBA to allow the manual data entry

Posted on 2015-02-19
14
43 Views
Last Modified: 2016-02-10
Hi,

I recently had VBA created to auto populate/fill down data.  I now need to see if it possible to allow the user to overwrite the data that is being populated.  The data is located in column H.  Below is the VBA.  I will also attach the workbook (referencing the Issue Log tab and column h - Ship To)

Private Sub Worksheet_Change(ByVal Target As Range)

With Application
    .EnableEvents = False
    .ScreenUpdating = False
    .DisplayAlerts = False
End With

Dim WS As Worksheet
Dim LastRow As Long
Dim I As Long

'Set ws = ThisWorkbook.Sheets("ISSUE LOG")
Set WS = Sheets("ISSUE LOG")

' get the last row from column A that has a value
LastRow = WS.Range("C" & WS.Rows.Count).End(xlUp).Row
If LastRow < Target.Row Then LastRow = Target.Row

' use the last row to determine how far down to extend the formula
'    ws.Range("A9:A" & lastRow).Formula = "=row()"

If Not Intersect(Target, WS.Columns(3)) Is Nothing Then
    WS.Range("A9:A" & LastRow).Formula = "=IF(C9<>"""",COUNTA($C$9:C9)&""."","""")"
    WS.Range("H9:H" & LastRow).Formula = "=$C$4"
End If

' Look to see if a cell in either columns A through B has been changed
If Not Intersect(Target, Range("A9:H" & LastRow)) Is Nothing Then
    Select Case True
       ' a is blank and b is not blank  ---- a should always be populated,
         ' but on the off chance that it is not set to N2
        Case WS.Cells(Target.Row, 1) = "" And WS.Cells(Target.Row, 2) <> ""
             WS.Cells(Target.Row, 6) = WS.Range("N2")
        ' a is not blank and b is blank set to current date
        Case WS.Cells(Target.Row, 1) <> "" And WS.Cells(Target.Row, 2) = ""
             WS.Cells(Target.Row, 6) = Now
        ' a is not blank and b is not blank set to N2
        Case WS.Cells(Target.Row, 1) <> "" And WS.Cells(Target.Row, 2) <> ""
             WS.Cells(Target.Row, 6) = WS.Range("N2")
        ' a is blank and b is blank set to blank
        Case WS.Cells(Target.Row, 1) = "" And WS.Cells(Target.Row, 2) = ""
             WS.Cells(Target.Row, 6) = ""
    End Select

End If

For I = 9 To LastRow
    If WS.Range("C" & I).Value <> "" Then
        WS.Range("H" & I).Value = WS.Range("C4") & Chr(10) & WS.Range("C5") & Chr(10) & WS.Range("C6") & " " & WS.Range("E6")
        WS.Range("H" & I).RowHeight = 71
    Else
        WS.Range("H" & I).Value = ""
        WS.Range("H" & I).RowHeight = 15
    End If
Next I

With Application
    .EnableEvents = True
    .ScreenUpdating = True
    .DisplayAlerts = True
End With

End Sub

Open in new window

EE-Test-Snag-2015.02.19xls.xls
0
Comment
Question by:jmac001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 4
14 Comments
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40619049
Why can't the user just type over what's there?
0
 

Author Comment

by:jmac001
ID: 40619072
I did try to overwrite, but it reverted back to data that was being pulled down.
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40619087
In the Worksheet_Change event change

For I = 9 To LastRow
    If WS.Range("C" & I).Value <> "" Then
        WS.Range("H" & I).Value = WS.Range("C4") & Chr(10) & WS.Range("C5") & Chr(10) & WS.Range("C6") & " " & WS.Range("E6")
        WS.Range("H" & I).RowHeight = 71
    Else
        WS.Range("H" & I).Value = ""
        WS.Range("H" & I).RowHeight = 15
    End If
Next I

Open in new window


to

If WS.Range("C" & LastRow).Value <> "" Then
    WS.Range("H" & LastRow).Value = WS.Range("C4") & Chr(10) & WS.Range("C5") & Chr(10) & WS.Range("C6") & " " & WS.Range("E6")
    WS.Range("H" & LastRow).RowHeight = 71
Else
    WS.Range("H" & LastRow).Value = ""
    WS.Range("H" & LastRow).RowHeight = 15
End If

Open in new window

0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:jmac001
ID: 40619141
Taking out the For/Next does allow for the data to be overwritten, but only the first line (address) is now being copied down and not the contact person and contact details.
0
 
LVL 30

Expert Comment

by:gowflow
ID: 40619165
yes because the routine pulls the data directly each time you activate yes in SNAG LIST and also each time you change anything in SNAG LOG it still go thru this same routine reason why you keep on getting this updated.

Now question:
When do we get the formulas only when SNAG LIST is avctivated ? and if user changes anything in SNAG LOG then you want to take what the user does and not the formulas

Right ??
gowflow
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40619188
Are you sure? Did you copy the new code correctly? I ask because this code
For I = 9 To LastRow
    If WS.Range("C" & I).Value <> "" Then
        WS.Range("H" & I).Value = WS.Range("C4") & Chr(10) & WS.Range("C5") & Chr(10) & WS.Range("C6") & " " & WS.Range("E6")
        WS.Range("H" & I).RowHeight = 71
    Else
        WS.Range("H" & I).Value = ""
        WS.Range("H" & I).RowHeight = 15
    End If
Next I

Open in new window

was transferring the address (C4), the person (C5), the phone (C6) and the email (E6) to every row any time a change
was made anyplace on the sheet while the new code
If WS.Range("C" & LastRow).Value <> "" Then
    WS.Range("H" & LastRow).Value = WS.Range("C4") & Chr(10) & WS.Range("C5") & Chr(10) & WS.Range("C6") & " " & WS.Range("E6")
    WS.Range("H" & LastRow).RowHeight = 71
Else
    WS.Range("H" & LastRow).Value = ""
    WS.Range("H" & LastRow).RowHeight = 15
End If

Open in new window

does exactly the same thing except it only affects the last row.
0
 

Author Comment

by:jmac001
ID: 40619267
Gowflow not sure that I fully understand the questions that you are asking,  What formula are you referring to?

Martin I copied the just as you have it above.
0
 
LVL 30

Expert Comment

by:gowflow
ID: 40619575
ok here is my question rephrasing:

I understand that when you put yes in sheet SNAG LIST in Col S it is supposed to put the item in sheet ISSUE LOG at the last row and put also the formula for the address in col H ship to.

Shall we keep this going ?

and when do we prevent the formula of the ship to to being automatically put when the user make his own changes in sheet LIST LOG ???

or  ..?? then clarify.

gowflow
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40619649
@jmac001: Please remind me how to get a new row to the Issue Log because I changed one of the "no" to "Yes" on the Snag List and nothing was added to the Issue Log.
0
 

Author Comment

by:jmac001
ID: 40619863
Gowflow, Yes to the first question.   Would it be difficult to have it keep populating and if it needs to be changed the user can go back and update after it has been populated?

Martin - need to have yes in column S and a comment in PM comment section
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40619908
It works for me. I just added this.
???
0
 
LVL 30

Accepted Solution

by:
gowflow earned 500 total points
ID: 40620015
ok here it is please try this version.
gowflow
Test-Snag-Template-V03.xls
0
 

Author Closing Comment

by:jmac001
ID: 40622161
Thanks again for your help Gowflow.

Martin decided to give all the points to Gowflow since I couldn't get your solution to work.
0
 
LVL 30

Expert Comment

by:gowflow
ID: 40622712
Tks and glad I could help.
gowflow
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

732 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