Assistance with Looping Needed

Philip1957

Board Regular
Joined
Sep 30, 2014
Messages
182
Office Version
  1. 365
Platform
  1. Windows
Greetings,

I have some code that works, but but now I need to make it loop upwards through the blank cells and stop before overwriting the first non-blank cell. I just can't seem to figure out that whole "i = / Next i" thing.

Also, in the last "Else" statement if the cell (0,-13) from Active is blank I really don't want to write the string "Machine" in it. Is there a way to write an "Else Unless" statement?

Any assistance would be greatly appreciated.

Code:
Sub Assign_Category()

    Dim DfctCode As String
    
'    Select the Data worksheet  (Works)
    ActiveWorkbook.Sheets("Data").Select
    
'    Find the last Row  (Works)
    Selection.SpecialCells(xlCellTypeLastCell).Select
    
'    Paste category based on defect code  (Works)
    DfctCode = ActiveCell.Offset(0, -13)
            
            If InStr(DfctCode, "I") > 0 Then
            ActiveCell.Value = "Vendor"
            
            ElseIf InStr(DfctCode, "5") > 0 Or InStr(DfctCode, "22") > 0 _
            Or InStr(DfctCode, "26") > 0 Or InStr(DfctCode, "29") > 0 _
            Or InStr(DfctCode, "31") > 0 Then
            ActiveCell.Value = "Operator"
            
            ElseIf InStr(DfctCode, "I") > 0 Then
            ActiveCell.Value = "Vendor"

            Else: ActiveCell.Value = "Machine"
           
            End If
         
End Sub

Thank you for your time.

~ Phil
 
Thanks for the explanation. Every little bit of VBA knowledge helps.

I actually have a reference file in Word where I paste code and add notes using the comment tool meant for reviewing documents. Between that and my VBA for Dummies book, I am slowly getting better at coding.

~ Phil
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Thanks for the explanation. Every little bit of VBA knowledge helps.

I actually have a reference file in Word where I paste code and add notes using the comment tool meant for reviewing documents. Between that and my VBA for Dummies book, I am slowly getting better at coding.

~ Phil

Very useful to know for people who use Microsoft office. When i first starting learning VBA i worked in payroll and pretty much automated all my work. Then i started building little applications in Access. I even built a few WinForm applications in Visual Studio because the coding language VB.net is very very similar to VBA.
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,362
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top