Solved

Tweak Existing VBA to allow the manual data entry

Posted on 2015-02-19
14
45 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 48

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 48

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 31

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 48

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 31

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 48

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 48

Expert Comment

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

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 31

Expert Comment

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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 the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

627 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