VBA Find column by header name and autofill column from inputbox to the last row

Addictions

Board Regular
Joined
May 27, 2018
Messages
60
Office Version
  1. 365
Hello,

I am trying to find VBA code which would find a header by name and then autofill that column from input box value to the last row.
Currently I am using below code to replace value in column PostalCode by value from inputbox. It replaces "United Kingdom" in Column PostalCode with value from inputbox. However I would want to autofill that column from inputbox instead of replacing it because value maybe different than "United Kingdom".


Sub Test()
Dim i As String
Dim k As String
Dim rngAddress As Range
i = "United Kingdom"
k = InputBox("Provide Postal Code")


Set rngAddress = Range("1:1").Find("PostalCode")
Range(rngAddress, rngAddress.End(xlDown)).Replace what:=i, replacement:=k, lookat:=xlPart, MatchCase:=False
End Sub
 
Last edited:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
How about
Code:
Sub Addictions()
   Dim Pcode As String
   Dim Fnd As Range
   
   Pcode = InputBox("Provide Postal Code")
   Set Fnd = Range("1:1").Find("PostalCode", , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then
      Fnd.Offset(1).Resize(Range("A" & Rows.Count).End(xlUp).Row - 1).Value = Pcode
   End If
End Sub
 
Upvote 0
This is great. Thank you so much for such a quick help.

I also would want ask for help with one more thing.
The process is the same. The header name is "Custom SKU" and I would like to provide value to inputbox and column would autofill but with sequence instead.

Example:
input value is Image0001
Results:
Image0001
Image0002
Image0003
Image0004 etc
 
Last edited:
Upvote 0
How about
Code:
Sub Addictions()
   Dim Pcode As String, Sku As String
   Dim Fnd As Range
   
   Pcode = InputBox("Provide Postal Code")
      Sku = InputBox("Provide SKU")
   Set Fnd = Range("1:1").Find("PostalCode", , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then
      Fnd.Offset(1).Resize(Range("A" & Rows.Count).End(xlUp).Row - 1).Value = Pcode
   End If
   Set Fnd = Range("1:1").Find("Custom SKU", , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then
      Fnd.Offset(1).Value = Sku
      Fnd.Offset(1).AutoFill Fnd.Offset(1).Resize(Range("A" & Rows.Count).End(xlUp).Row - 1), xlFillSeries
   End If
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

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