?
Solved

Insert text when conditions are met

Posted on 2013-06-12
4
Medium Priority
?
214 Views
Last Modified: 2013-06-13
I need help with vba to do the following

If  Number in column C of sheet4 matches sheet19 column A
and sheet4 column AQ = "file"
and column AP of Sheet4 is not null
then place "1" in column D of sheet19
to end of row of column A of sheet19

---------------

this is what I have so far

  Dim lngRow                                            As Long
  Dim objCell                                           As Range
  Dim objRange                                          As Range
 
  On Error Resume Next
  Application.ScreenUpdating = False
 
  Set objRange = Range(Sheets("sheet4").[c3], Sheets("sheet4").Cells(Sheets("Sheet4").Cells.Rows.Count, "C").End(xlUp))
 
 If Not (objRange Is Nothing) Then
     Sheets("Missing 3PM Prices").Select
 
     For lngRow = Cells(Cells.Rows.Count, 1).End(xlUp).Row To 2& Step -1&
 
         Set objCell = Nothing
         Set objCell = objRange.Find(What:=Cells(lngRow, "A"))
     
         If Not (objCell Is Nothing) Then
            If Not (IsEmpty(Sheets("Sheet4").Cells(objCell.Row, "AP")))    



Thanks in advance
0
Comment
Question by:leezac
[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
  • 2
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
JP earned 2000 total points
ID: 39244180
Try the code attached.
Sub Data_Check()
applcation.ScreenUpdating = False
Dim lngRow As Long, sh1 As String, sh2 As String, sh3 As String
lngRow = Sheets(sh1).UsedRange.Rows.Count
sh1 = "Sheet4"
sh2 = "Sheet19"
sh3 = "Missing 3PM Prices"

If Sheets(sh1).[c3] = "" Then
    Sheets(sh3).Select
Else
    For i = lngRow To 2 Step -1
        If Sheets(sh1).Cells(i, "C").Value = Sheets(sh2).Cells(i, "A").Value _
            And Sheets(sh1).Cells(i, "AQ").Value = "file" _
            And Sheets(sh1).Cells(i, "AP").Value <> "" Then
        Sheets(sh2).Range("D" & i & ":K" & i).Value = 1 'REPLACE K WITH LAST COLUMN
    Next i
End If
End Sub

Open in new window

0
 

Author Comment

by:leezac
ID: 39244493
I modified - did not need sheet3 - posted too much information in first post.  Works except I need only Column D to be inserted with "1"
 I do not know how to change the line below
Sheets(sh2).Range("D" & ":D" & i).Value = 1
__________________________________________________________________



Application.ScreenUpdating = False
Dim lngRow As Long, sh1 As String, sh2 As String
sh1 = "Compare"
sh2 = "tmp"
 
lngRow = Sheets(sh1).UsedRange.Rows.Count


    For i = lngRow To 2 Step -1
        If Sheets(sh1).Cells(i, "C").Value = Sheets(sh2).Cells(i, "A").Value _
            And Sheets(sh1).Cells(i, "AQ").Value = "file" _
            And Sheets(sh1).Cells(i, "AP").Value <> "" Then
        Sheets(sh2).Range("D" & ":D" & i).Value = 1
 End If
Next
0
 
LVL 14

Expert Comment

by:JP
ID: 39244977
Use this line
Sheets(sh2).cells(i, "D").value = 1

I thought you wanted from D to Last Column, no biggie.
0
 

Author Comment

by:leezac
ID: 39245028
Thanks
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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 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