+ Reply to Thread
Results 1 to 7 of 7

Macro - Ignore Cells with a value in?

Hybrid View

  1. #1
    Registered User
    Join Date
    11-16-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    34

    Macro - Ignore Cells with a value in?

    Hi there,

    I'm currently using a macro to determine what information is missing. However, the macro I'm using is overwriting all values. Is there anyway I can get it to ignore cells that have a value in? I've attached an example spreadsheet with the code I'm using.

    Below is the code I'm using:

    Sub Dave()
     Dim ws As Worksheet
     Dim rng As Variant
     Dim LR As Long
            Application.ScreenUpdating = 0
            
                Set ws = Worksheets("Sheet1")
                LR = ws.UsedRange.Rows.Count
                rng = ws.Range("A2:T" & LR).Value
                
                    With ws
                      .Cells(2, 2).Resize(LR).FormulaR1C1 = "=IF(RC[-1]<>"""",""Information Required"","""")"
                      .Cells(2, 3).Resize(LR).FormulaR1C1 = "=IF(RC[-2]<>"""",""Information Required"","""")"
                      .Cells(2, 4).Resize(LR).FormulaR1C1 = "=IF(RC[-3]<>"""",""Information Required"","""")"
                      .Cells(2, 5).Resize(LR).FormulaR1C1 = "=IF(RC[-4]<>"""",""Information Required"","""")"
                      .Cells(2, 6).Resize(LR).FormulaR1C1 = "=IF(RC[-5]<>"""",""Information Required"","""")"
                      .Cells(2, 7).Resize(LR).FormulaR1C1 = "=IF(RC[-6]<>"""",""Information Required"","""")"
                      .Cells(2, 8).Resize(LR).FormulaR1C1 = "=IF(RC[-7]<>"""",""Information Required"","""")"
                      .Cells(2, 9).Resize(LR).FormulaR1C1 = "=IF(RC[-8]<>"""",""Information Required"","""")"
                      .Cells(2, 10).Resize(LR).FormulaR1C1 = "=IF(RC[-9]<>"""",""Information Required"","""")"
                      .Cells(2, 11).Resize(LR).FormulaR1C1 = "=IF(RC[-10]<>"""",""Information Required"","""")"
                      .Cells(2, 12).Resize(LR).FormulaR1C1 = "=IF(RC[-11]<>"""",""Information Required"","""")"
                      .Cells(2, 13).Resize(LR).FormulaR1C1 = "=IF(RC[-12]<>"""",""Information Required"","""")"
                      .Cells(2, 14).Resize(LR).FormulaR1C1 = "=IF(RC[-13]<>"""",""Information Required"","""")"
                      .Cells(2, 15).Resize(LR).FormulaR1C1 = "=IF(RC[-14]<>"""",""Information Required"","""")"
                      .Cells(2, 16).Resize(LR).FormulaR1C1 = "=IF(RC[-15]<>"""",""Information Required"","""")"
                      .Cells(2, 17).Resize(LR).FormulaR1C1 = "=IF(RC[-16]<>"""",""Information Required"","""")"
                      .Cells(2, 18).Resize(LR).FormulaR1C1 = "=IF(RC[-17]<>"""",""Information Required"","""")"
                      .Cells(2, 19).Resize(LR).FormulaR1C1 = "=IF(RC[-18]<>"""",""Information Required"","""")"
                    End With
                ws.Range("A2:T" & LR).Value = ws.Range("A2:T" & LR).Value
                        With ws.Range("D2:T" & LR).Validation
                            .Delete
                            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                            xlBetween, Formula1:="=$T$3:$T$8"
                            .IgnoreBlank = True
                            .InCellDropdown = True
                            .InputTitle = ""
                            .ErrorTitle = ""
                            .InputMessage = ""
                            .ErrorMessage = ""
                            .ShowInput = True
                            .ShowError = False
                        End With
            Application.ScreenUpdating = 1
    End Sub
    Thank you in advance for the help!
    Attached Files Attached Files
    Last edited by revenge4ash89; 12-09-2011 at 12:17 PM.

  2. #2
    Forum Contributor wamp's Avatar
    Join Date
    11-10-2008
    Location
    Norway
    MS-Off Ver
    97, 2000 & 2003 (diff. workstations)
    Posts
    184

    Re: Macro - Ignore Cells with a value in?

    read the rules, then alter your post accordingly
    _______________________________________________
    Remember:

    Read the rules!

    Use code tags! Place [CODE] before the first line of code and [/CODE] after the last line of code.

    Mark your post [SOLVED] if it has been answered satisfactorily.
    To do this, click EDIT in your original post, click GO ADVANCED and set the PREFIX. It helps everybody!

    If you are approve (or disapprove) of any members response to your problem, please click the star icon underneath their post and comment. It matters.

  3. #3
    Registered User
    Join Date
    11-16-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    34

    Re: Macro - Ignore Cells with a value in?

    Sorry, my brain is fully functioning today - Friday feeling I guess. I've corrected the post
    Last edited by revenge4ash89; 12-09-2011 at 09:10 AM.

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro - Ignore Cells with a value in?

    You can use -
     if cells(2,2)<>"" then ....
    While looking through your code, i find that you have repeated the same line over and over again and incremented by 1. Your code can be structured better if you explain your requirement...and we can help you out.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  5. #5
    Registered User
    Join Date
    11-16-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    34

    Re: Macro - Ignore Cells with a value in?

    Hi Arlu,

    I think I've over complicated it, but basically I just wanted it to post "information required" in column B - S if there is a value in column A. However, I don't want "information required" to overwrite a cell if it already has a value in.

    Sorry if that's unclear, I'm very new to this programming language as you can tell.

    Thanks for the help!

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Macro - Ignore Cells with a value in?

    I changed your code to the below - Only the initial loop.
    Sub Dave()
     Dim ws As Worksheet
     Dim rng As Variant
     Dim LR As Long
            Application.ScreenUpdating = 0
            
                Set ws = Worksheets("Sheet1")
                LR = ws.UsedRange.Rows.Count
                LC = ws.UsedRange.Columns.Count
                rng = ws.Range("A2:T" & LR).Value
                          
                With ws
                    For i = 2 To LR
                        For j = 2 To LC - 3
                            If .Cells(i, j).Value = "" Then .Cells(i, j).FormulaR1C1 = "=If(RC[-1]<>"""",""Test"","""")"
                        Next j
                    Next i
                   
                    End With
                ws.Range("A2:T" & LR).Value = ws.Range("A2:T" & LR).Value
                        With ws.Range("D2:T" & LR).Validation
                            .Delete
                            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                            xlBetween, Formula1:="=$T$3:$T$8"
                            .IgnoreBlank = True
                            .InCellDropdown = True
                            .InputTitle = ""
                            .ErrorTitle = ""
                            .InputMessage = ""
                            .ErrorMessage = ""
                            .ShowInput = True
                            .ShowError = False
                        End With
            Application.ScreenUpdating = 1
    End Sub

  7. #7
    Registered User
    Join Date
    11-16-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    34

    Re: Macro - Ignore Cells with a value in?

    Arlu that works absolutely perfectly!!! Thank you so much for the help, I can't tell you how much I appreciate it!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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