Excel VBA - Fill data in a Range based on value that has been picked from another search

Zendan21

New Member
Joined
Jun 15, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am after a VBA code that will fill in data for the 'Location' Column. The value of this data to be filled in will pick from the 'Manufacturing method' offset value.

If the 'Location' value is blank I want to search the 'Manufacturing method' column to find the value 'Assembled-House' once this value is found I want the use the 'Location' value offset of the Assembled-House to fill in the cells that are blank until Assembled-House value is found again.

So if done correctly the macro would fill in the blank values for the first Assembled-house group as '10', the second group have no blanks so these would be ignored and the third group blanks as '3 > G > 8'

I have the below Code which is very basic and will fill data based on the value above it however that isn't always correct to the group it needs to pick from


Thank you for the help!



VBA Code:
Option Explicit

Sub Location_Fill()

Application.ScreenUpdating = False
Dim c  As Range

    For Each c In Range("I2:I" & Cells(Rows.Count, "I").End(xlUp).Row)

'adds location flow to any blank cells
        If c.Value < 1 And c.Offset(-1, 0) Like "*JP Bench*" Then c.Value = "JP Bench"
        If c.Value < 1 And c.Offset(-1, 0) Like "*JP*" Then c.Value = "Jig & Press"
        If c.Value < 1 And c.Offset(-1, 0) Like "*10.1*" Then c.Value = "F > 10.1"
        If c.Value < 1 And c.Offset(-1, 0) Like "*10.2*" Then c.Value = "F > 10.2"
        If c.Value < 1 And c.Offset(-1, 0) Like "*10.3*" Then c.Value = "F > 10.3"
        If c.Value < 1 And c.Offset(-1, 0) Like "*10*" Then c.Value = "F > 10"
        If c.Value < 1 And c.Offset(-1, 0) Like "*1*" Then c.Value = "F > 1"
        If c.Value < 1 And c.Offset(-1, 0) Like "*2*" Then c.Value = "F > 2"
        If c.Value < 1 And c.Offset(-1, 0) Like "*3*" Then c.Value = "F > 3"
        If c.Value < 1 And c.Offset(-1, 0) Like "*4*" Then c.Value = "F > 4"
        If c.Value < 1 And c.Offset(-1, 0) Like "*5*" Then c.Value = "F > 5"
        If c.Value < 1 And c.Offset(-1, 0) Like "*6*" Then c.Value = "F > 6"
        If c.Value < 1 And c.Offset(-1, 0) Like "*7*" Then c.Value = "F > 7"
        If c.Value < 1 And c.Offset(-1, 0) Like "*8*" Then c.Value = "F > 8"
        If c.Value < 1 And c.Offset(-1, 0) Like "*9*" Then c.Value = "F > 9"
        
    Next
    
Application.ScreenUpdating = True

End Sub
 

Attachments

  • Cutlist_Location_Fill.jpg
    Cutlist_Location_Fill.jpg
    130.2 KB · Views: 26

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,224,300
Messages
6,177,755
Members
452,798
Latest member
mlance617

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